argument-passing

Not Possible to Reference self in a Method Declaration?

I wanted to write a method with an argument that defaults to a member variable like so: def method(self, arg1=0, arg2=self.member): Apparently this is not allowed. Should I write it a different way, or perhaps use a value of arg2 to signal when to use the member variable? ...

Problem using void pointer as a function argument

Hi, I can't understand this result... The code: void foo(void * key, size_t key_sz) { HashItem *item = malloc(sizeof(HashItem)); printf("[%d]\n", (int)key); ... item->key = malloc(key_sz); memcpy(item->key, key, key_sz); } void bar(int num) { foo(&num, sizeof(int)); } And I do this call: bar(900011009); ...

R: Pass by reference

Can you pass by reference with "R" ? for example, in the following code: setClass("MyClass", representation( name="character" )) instance1 <-new("MyClass",name="Hello1") instance2 <-new("MyClass",name="Hello2") array = c(instance1,instance2) instance1 array instance1@name="World!" instance1 array the output is > ins...

how to create a string literal as a function argument via string concatenation in c

I need to pass a string literal to a function myfunction("arg1" DEF_CHAR "arg1"); now part of that constructed string literal needs to be a function return stmp = createString(); myfunction("arg1" stmp "arg2"); //oh that doesn't work either is there any way to do this in one line? myfunction("arg1" createString() "arg2"); //what i...

Process.Start - Pass html code to exe as argument

Hello, I am using the code below to start a executable file from a windows service and I need to pass html code (stored in a variable) as an argument. I am escaping with double quotes but this is not working. What do I need to do in order to pass this correctly? Thanks in advance for any guidance that is offered. Inside the service: Pr...

How to Use an Environment Variable as an Environment Variable Name

Hi, In my pursuit of a solution to another environment-variable/batch-file related problem, I have once again come across a problem I have visited before (but cannot for the life of me remember how, or even if I solved it). Say you have two BAT files (or one batch file and the command line). How can one pass an environment variable nam...

How can multiple variables be passed to a function cleanly in C?

I am working on an embedded system that has different output capabilities (digital out, serial, analog, etc). I am trying to figure out a clean way to pass many of the variables that will control those functions. I don't need to pass ALL of them too often, but I was hoping to have a function that would read the input data (in this case...

learning C++ from Java , trying to make a linked list.

I just started learning C++ (coming from Java) and am having some serious problems with doing anything :P Currently, i am attempting to make a linked list, but must be doing something stupid cause i keep getting "void value not ignored as it ought to be" compile errors (i have it marked where it is throwing it bellow). If anyone could he...

Passing arguments to a C program

Hi All, I was writing a C program where I use 6 variables a,b,c,d,e,f a,b,c are constant values which I should pass as an arguments from the command line. d,e,f are going to be size of arrays of a structure. typedef struct { blah blah } ex; ex ex0[d]; I am very confused about how to pass all these as argument. Right now I have ...

Difference of function argument as (const int &) and (int & a) in C++

I know that if you write void function_name(int& a), then function will not do local copy of your variable passed as argument. Also have met in literature that you should write void function_name(const int & a) in order to say compiler, that I dont want the variable passed as argument to be copied. So my question: what is the difference...

What's wrong with my using argc/argv this way in c?

This works: int main( int argc, char *argv[]) { .... gtk_init(&argc, &argv); .... But this doesn't: int WINAPI WinMain (HINSTANCE p1, HINSTANCE p2, LPSTR argv, int argc) { .... gtk_init(&argc, &argv); .... Can someone point out what's wrong there? ...

What is the difference between array parameters in C

Hi, what is the difference between following function declarations, which create and return the array in C/C++? Both methods create the array and fill it with proper values and returns true if everything passed. bool getArray(int* array); bool getArray(int* array[]); Thanks Best Regards, STeN ...

Passing an empty IEnumerable argument to a method

I have this method (simplified): void DoSomething(IEnumerable<int> numbers); And I invoke it like this: DoSomething(condition==true?results:new List<int>()); The variable results is formed with a LINQ select condition (IEnumerable). I was wondering is this List<int>() the best way (the fastest?) to pass an empty collection, or is ...

Convert c++ argument to int

Hello, I have a small c++ program that needs to get and argument and convert it to an int. Here is my code so far: #include <iostream> using namespace std; int main(int argc,int argvx[]) { int i=1; int answer = 23; int temp; // decode arguments if(argc < 2) { printf("You must provide at least one argument...

Passing big multi-dimensional array to function in C

Hi, I'm having trouble passing a big array to a function in C. I declare: int image[height][width][3]={}; where height and width can be as big as 1500. And when I call: foo((void *)image,height,width); which is declared as follows: int *foo(const int *inputImage, int h, int w); I get segmentation fault error. What's strange is ...

Forced naming of parameters in python

In python you may have a function definition: def info(object, spacing=10, collapse=1) which could be called in any of the following ways: info(odbchelper) info(odbchelper, 12) info(odbchelper, collapse=0) info(spacing=15, object=odbchelper) thanks to python's allowing of any-order argume...

Python pass in variable assignments through a function wrapper

So I know that you can wrap a function around another function by doing the following. def foo(a=4,b=3): return a+b def bar(func,args): return func(*args) so if I then called bar(foo,[2,3]) the return value would be 5. I am wondering is there a way to use bar to call foo with foo(b=12) where bar would return 16? Does this m...

Pass-by-value argument in message expression is undefined

Hello. I'm developing an iPhone application and I getting that warning at method: NSNumber *latitudeValue; NSNumber *longitudeValue; [self obtainLatitude:latitudeValue longitude:longitudeValue]; The method is declared as follows: - (void) obtainLatitude:(NSNumber *)latitudeValue longitude:(NSNumber *)longitudeValue { NSNumberF...

Keyword argument in unpacking argument list/dict cases in Python

For python, I could use unpacking arguments as follows. def hello(x, *y, **z): print 'x', x print 'y', y print 'z', z hello(1, *[1,2,3], a=1,b=2,c=3) hello(1, *(1,2,3), **{'a':1,'b':2,'c':3}) x = 1 y = (1, 2, 3) z = {'a': 1, 'c': 3, 'b': 2} But, I got an error if I use keyword argument as follows. hello(x=1, *(1,2,...

PyArg_ParseTuple causing segmentation fault

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_ParseTupl...