Click to See Complete Forum and Search --> : [C] void(*pfunc)(...);


Quitter3
June 21st, 2002, 03:44 AM
I have made a testprogram in Visual Studio, which uses a functionpointer like this:

Str1, Str2 and Str3 contain the functionaddresses retreived out of the mapfile.

#include "stdargs.h"

void (*pfunc)(...);

memcpy(&pfunc,Str1,4);
pfunc();

memcpy(&pfunc,Str2,4);
pfunc(20);

memcpy(&pfunc,Str3,4);
pfunc(20, "test");

This works great.

But I really want to use this in an embedded ARM system. So I wrote the same code in an ANSI C file for ARM.
For compiling I use the ADS compiler. But this compiler errors on the (...) in the pointer declaration.

When I leave the ... away like this:

void (*pfunc)();

it does not come up with any errors. But I still call functions with 1 or 2 parameters.

Can anyone tell me if this is possible in ANSI C?
And if it is, is it a compiler bug or am I doing something wrong?

zdf
June 21st, 2002, 05:45 AM
Standard C requires at least one fixed argument. So as you can start parsing the rest of arguments.


int foo( int arg1, ... )
{
va_list list;
va_start(list, arg1 );
/*...*/
}


:)

PaulWendt
June 21st, 2002, 06:26 AM
... in C, if you have NO function arguments in the declaration, that means the function can take any number of arguments; in C++, it means that the function takes NO arguments, I believe.

zdf
June 21st, 2002, 06:35 AM
Originally posted by PaulWendt
... in C, if you have NO function arguments in the declaration, that means the function can take any number of arguments; in C++, it means that the function takes NO arguments, I believe.

Does your compiler successfully compile the code below?

int foo(...)
{
}


:)

Quitter3
June 21st, 2002, 06:43 AM
Originally posted by zdf


Does your compiler successfully compile the code below?

int foo(...)
{
}


:)

Yes it does. But my problem is already answered.

... in C, if you have NO function arguments in the declaration, that means the function can take any number of arguments; in C++, it means that the function takes NO arguments, I believe.

This I did not know. I have not been able to find it either. THanks for the quick answers.