variadic-functions

C# invoking CPP function with unknown number of args from CPP

i have a function in CPP with the following prototype: char* complexFunction(char* arg1, ...); i import it from a C# using DLLImport attribute. the questions are: how do i define the prototype in the C# (under the DLLImport attribute)? how do i pass the arguments to this function? thanks ...

Are there any programming languages with functions with variable arguments not at the end?

Python, C++, Scheme, and others all let you define functions that take a variable number of arguments at the end of the argument list... def function(a, b, *args): #etc... ...that can be called as followed: function(1, 2) function(1, 2, 5, 6, 7, 8) etc... Are there any languages that allow you to do variadic functions with the ...

"Repassing" function arguments

Hi all! I'm doing this class assignment, using classic C, and am stuck with this problem about callback functions that take variable arguments count and type. Basically, I'm working on a Hashed Tree (a tree where each of the nodes is a hash tree), and I have a certain traversal strategy that will be used multiple times for different pur...

Passing an ellipsis to another variadic function

I have approximately 30 variadic functions. Each one accepts a path as the final argument, i.e.: bool do_foo(struct *f, int q, const char *fmt, ...) In each function, I have to check that the expanded format is less then or equal to a certain size. So, I find myself copy / pasting the same chunk of code to check for how many characters...

C++ Function Pointer issue

For some reason trying to pass a pointer to this function to a varadic function produces the following error: 1>c:\... : error C2664: 'PyArg_ParseTuple' : cannot convert parameter 3 from 'int (__cdecl *)(PyObject *,void *)' to '...' 1> Context does not allow for disambiguation of overloaded function PyArg_ParseTuple(args, "O&O&:...

Macro-producing macros in C?

I'd like to get the C preprocessor to generate macros for me (i.e., I'm using C99 only). I'd write a macro #define make_macro(in) <...magic here...> and when I put make_macro(name1) make_macro(name2) later in the code, it would expand to #define name1(...) name1_fn(name1_info, __VA_ARGS__) #define name2(...) name2_fn(name2_info, _...

What was the design decision for variadic functions needing an array?

I am curious and hopefully someone can shed somelight on this - but why do the C# functions that take 'params' have to be an array? I get that the objects in the parameters list are entered into an array but what if someone wants to create a variadic function that takes in an undefined number of array objects? Take this function for ex...

How to "pass on" a variable number of arguments to NSString's +stringWithFormat:

I would like to write a function in Objective-C such as the one below, that takes a variable number of arguments, and passes those arguments on to +stringWithFormat:. I know about vsnprintf, but that would imply converting the NSString 'format' to C and back (and would also mean converting the formatting placeholders within it as well......

Variadic function without specified first parameter?

Out of curiosity, I thought I'd try and write a basic C++ class that mimics C#'s multiple delegate pattern. The code below mostly does the job, with the nasty sacrifice of losing almost all type-safety, but having to use the initial dummy parameter to set up the va_list really seems a bit off. Is there a way to use va_list without this? ...

How to write a JS function that accepts and "forwards" variable number of parameters?

How do I write a Javascript function that accepts a variable number of parameters, and forwards all of those parameters to other anonymous functions? For example, consider the scenario of a method that fires an event: function fireStartedEvent(a,b,c,d,e,f,g,...) { for(var i = 0; i < startedListeners.length; i++) { started...

pass variable number of arguments in scala (2.8) case class to parent constructor

I was experimenting with variable constructor arguments for case classes in Scala, but am unable to pass them to the constructor of a case classes' parent: abstract case class Node(val blocks: (Node => Option[Node])*) case class Root(val elementBlocks: (Node => Option[Node])*) extends Node(elementBlocks) the above doesn't compile... i...

Variable Argument Lists in C++/CLI

How do I create a function which accepts a variable argument list in C++/CLI? I am looking to create a function which forwards most of it's arguments to String::Format. ...

PHP: variable-length argument list by reference?

Is it possible to create a PHP function that takes a variable number of parameters all of them by reference? It doesn't help me a function that receives by reference an array of values nor a function that takes its arguments wrapped in an object because I'm working on function composition and argument binding. Don't think about call-tim...

Variadic Macros : how to solve "too many actual parameters for macro.."

Ive been working on getting some of my code originally built on the mac to run under Visual Studio 2008 Express and have run into a weird problem with the variadic macros i use for my assert code : The macro is defined as : #define SH_ASSERT( assertID, exp, description, ... ) shAssertBasic( int(exp), assertID, description, __LINE__, _...

Calling cdecl Functions That Have Different Number of Arguments

I have functions that I wish to call based on some input. Each function has different number of arguments. In other words, if (strcmp(str, "funcA") == 0) funcA(a, b, c); else if (strcmp(str, "funcB") == 0) funcB(d); else if (strcmp(str, "funcC") == 0) funcC(f, g); This is a bit bulky and hard to maintain. Ideally, these are variadic f...

sscanf wrapping function to advance string pointer in C

I have a function that makes a series of calls to sscanf() and then, after each, updates the string pointer to point to the first character not consumed by sscanf() like so: if(sscanf(str, "%d%n", &fooInt, &length) != 1) { // error handling } str+=length; In order to clean it up and avoid duplicating this several times over, i'd l...

Ellipsis notation in C#?

Where can I get info about implementing my own methods that have the ellipsis notation, e.g. static void my_printf(char* format, ...) { } Also is that called ellipsis notation or is there a fancier name? ...

How can arguments to variadic functions be passed by reference in PHP?

Assuming it's possible, how would one pass arguments by reference to a variadic function without generating a warning in PHP? We can no longer use the '&' operator in a function call, otherwise I'd accept that (even though it would be error prone, should a coder forget it). What inspired this is are old MySQLi wrapper classes that I une...

Is it possible to have a variadic function in C with no non-variadic parameter?

I have the following function: void doStuff(int unusedParameter, ...) { va_list params; va_start(params, unusedParameter); /* ... */ va_end(params); } As part of a refactor, I'd like to remove the unused parameter without otherwise changing the implementation of the function. As far as I can tell, it's impossible to us...

JRuby: how to call a Java variadic function without optional arguments

I have a function with a signature similar to String.format(String, Object...). I want to call this function from JRuby without the last parameters (since it is optional), but my code throws an ArgumentError (wrong # of arguments(1 for 2)) Is there a way to call this function with only 1 argument just like I would do in Java? ...