Error: invalid conversion from 'void (*) (...)' to 'void (*) ()'

with this problem on Mac with gcc 4.0.1 build 5370, Xcode 2.5. Code snippet:

there is a declared function, the second parameter causes the problem:

void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) 

calls it this way:

typedef void (*FuncPtr)();
FuncPtr func = some_function_pointer;
ffi_call(null, func, ...);

causes an error in the third line. Looks like: "void func (void)" is different from "void func ()" for gcc 4.0.1

Any ideas on any gcc switch or just a gcc update to help? Thanks for the help of Honza B.

+3
source share
3 answers

If you program in C, void func()and void func(void)do not match. void func()equivalent to void func(...). (This is different from C ++.)

, ++ ( , ), FuncPtr typedef typedef void (*FuncPtr)(void).

+3

C, .


C , C. , , , .

C ( "K & R C" ) , : f(){/* stuff */}

double f(d)
double d;
{ stuff }

(), (d), , .

C89- C99- double f(double); double f(double d) { /* stuff */} . double f(void) - ANSI , double f() - "", .

0

, void func(void) void func().

void (*)func() . , C.

. , , ( ), .

0
source

Source: https://habr.com/ru/post/1718828/


All Articles