argument-passing

PyArg_ParseTuple causing segmentation fault

荒凉一梦 提交于 2019-12-08 13:17:15
问题 I'm trying to call a c function from my extension and have narrowed the problem down to this test case. #import "Python.h" ... // Called from python with test_method(0, 0, 'TEST') static PyObject* test_method(PyObject *args) { int ok, x, y, size; const char *s; // this causes Segmentation fault //ok = PyArg_ParseTuple(args, "iis#", &x, &y, &s, &size); // also segfaults //if(ok) PyErr_SetString(PyExc_SystemError, 'Exception'); // this does not cause segfault but fills the variables with

Passing array argument to a function

旧街凉风 提交于 2019-12-08 10:28:44
问题 On calling the function int sum_array(int array[], int arr_length) { int sum = 0; while(--arr_length >= 0) sum += array[arr_length]; return sum; } in main function int main() { int b[10]; ... total = sum_array(b,10); ... } why passing the argument b , not b[] as sum_array(b[],10) ? NOTE : I have no knowledge of pointers. 回答1: In C, arrays are passed as a pointer to the first element. The type of b is array. When passing b , you're actually passing a pointer to the first element of the array.

Passing a FORTRAN object to C and vice versa

我是研究僧i 提交于 2019-12-08 05:34:08
问题 I have my Fortran object i.e. this%object%a this%object%b this%object%c I want to pass it to a code written in C, I am predominately a FORTRAN programmer and I have had very little exposure to C. I am using iso_c_binding to pass integers and arrays but now I need to pass objects. I define the object in the following way TYPE object INTEGER :: a INTEGER :: b INTEGER :: c END TYPE object 回答1: You can make interoperable types: use iso_c_binding TYPE, BIND(C) :: object INTEGER(c_int) :: a INTEGER

Right Way of Passing a 2D vector as an argument to a function in C++

对着背影说爱祢 提交于 2019-12-07 15:45:31
I'm trying to write a function that takes a 2D vector as an argument. This compiles just fine, but I get a segmentation fault whilst execution. //http://www.codechef.com/problems/SUMTRIAN #include<iostream> #include<algorithm> #include<vector> using namespace std; int max_sum_path(int maximum_rows,vector<vector<int> >& matrix,int row_index,int colm_index); int main() { vector<vector<int> > Triangle; int num_test_cases; cin>>num_test_cases; //to iterate over the test cases for(int i=0;i<num_test_cases;++i) { int max_rows; cin>>max_rows; //to build the 2d vector Triangle.resize(max_rows); for

Pass multiple files / folders from windows explorer to external application

可紊 提交于 2019-12-07 07:29:10
问题 Hi does anyone know how to get windows explorer to pass multiple files / folders through to an external app (c#) referenced in the registry? I am current able to act upon a single file / folder using the %1 syntax but not sure how to get explorer to pass through multiple items. Does anyone know how to do this? 回答1: When you select multiple files in Explorer, your shell context menu extension's IShellExtInit::Initialize method will be called and pdtobj contains the selection. Note writing

How can I pass arguments into SwingWorker?

若如初见. 提交于 2019-12-07 03:29:00
问题 I'm trying to implement Swing worker in my GUI. At the moment I have a JFrame containing a button. When this is pressed it should update a tab displayed and then run a program in the background thread. Here is what I have so far. class ClassA { private static void addRunButton() { JButton runButton = new JButton("Run"); runButton.setEnabled(false); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new ClassB().execute(); } }); mainWindow.add

How to pass an argument with space from bash script to bash script?

旧巷老猫 提交于 2019-12-06 09:13:37
问题 I have a script the manipulates data, creates arguments and sends them to a second script. One of the arguments contains a space. script1.sh: args=() args+=("A") args+=("1 2") args+=("B") . script2.sh ${args[@]} script2.sh: for f in "$@" do echo f=$f done I'd like to get "1 2" as single argument, but receive them separately: f=A f=1 f=2 f=B I tried also converting the input in script2 to list in=($@) and iterating over it using for f in ${in[@]} but got the same result. So, the problem might

What is the neatest way of passing flags to a Matlab function?

无人久伴 提交于 2019-12-06 09:05:09
问题 I'm designing a function that takes as argument one structure and any number of flags. The function will contain a couple of if s checking whether a specific flag is set. What is the neatest way to achieve this? I was thinking about passing the flags as separate string arguments. Is there a neater solution? 回答1: I would do it like using varargin and ismember : function foo(arg1,arg2,varargin) flag1=ismember('flag1',varargin); flag2=ismember('flag2',varargin); flag3=ismember('flag3',varargin);

static method as default parameter to a class method

荒凉一梦 提交于 2019-12-06 06:06:07
问题 My question is about two answers to another question: Using class/static methods as default parameter values within methods of the same class. I am trying to understand if there's really a difference between what the two answers do, and if so, what's the pros and cons of each. Question: how to use a class method as a default parameter to a method in the same class. Answer 1: use a function instead of a class method class X: def default_func(x): return True def test(self, func = default_func):

C++ how to pass 'this' to pointer reference

北城以北 提交于 2019-12-05 17:42:21
i have main class that i like to pass its pointer reference to on of the objects i creating but it gives me error : Error 1 error C2664: 'GameController::GameController(GameLayer *&)' : cannot convert parameter 1 from 'GameLayer *const ' to 'GameLayer *&' what i have in the GameLayer ( the main object ) m_pGameController = new GameController(this); and in the GameController i have this constructor GameController(GameLayer*& GameLayer) { setGameLayer(gameLayer); // to GameLayer memeber ) } the resone is i need to be able to modify the data in GameLayer from GameController (GUI stuff) First, the