LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic function input

Hallo,

I want to create a function, which has a dynamic input like: int FUNCTION (int input, ...)

But in my function I need the input like this way: int FUNCTION (int input1, int input2, int input3, and_so_on...)
I need to call all inputs with local variables.

Is there a possibility? a example?

thx
Florian
0 Kudos
Message 1 of 8
(4,165 Views)
sorry, I've forgotten:

how do this "..." exactly work in the function input??

thx Florian
0 Kudos
Message 2 of 8
(4,158 Views)
Seems that what you are looking for is a function that accepts a variable number of parameters. This can be accomplished with the use of va_start and other related macros.
For a sample function that uses them you can look at this post

You can find some discussion about the va_xx macrosin these links:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_va_arg.2c_.va_end.2c_.va_start.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_va_arg.2c_.va_end.2c_.va_start.asp


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 8
(4,147 Views)
Something like that ?
Regards,


int MyFunction(unsigned short int numberOfArguments,...)
//1) Assumes that all arguments are integers
//2) Assumes that you know the number of arguments when calling the function
{
unsigned short int i;
va_list ap;

if (numberOfArguments <1) return -1; //At least 1 arg.

va_start(ap,numberOfArguments);

for (i=0;i {
int input;
input = va_arg(ap,int);
printf("Arg[%d]: %d\n",i+1,input);
}

va_end(ap);

return(0);
}
0 Kudos
Message 4 of 8
(4,145 Views)
is the for-loop realy correct? because of the parameter list
0 Kudos
Message 5 of 8
(4,139 Views)
Of course no.
Some characters were lost in the reply
for (i=0;iis the correct loop.
0 Kudos
Message 6 of 8
(4,131 Views)
OK. Loop does not want to display properly.
Complete with:
i
Regards,
0 Kudos
Message 7 of 8
(4,129 Views)
Looks like some math symbols do not display.
Complete yoursef with i less than numberOfArguments
and next i.
Regards.
0 Kudos
Message 8 of 8
(4,127 Views)