V
viza
Hi
I have program1.c:
typedef int (*fn_t)(int);
int fn( int f ){
return f;
}
int main( void ){
fn_t f= fn;
return f( 0 );
}
and program2.c
typedef int (*fn_t)(int);
int fn( int f ){
return f;
}
int main( void ){
fn_t f= fn;
return (*f)( 0 );
}
They both compile with no errors/warnings/comments under
gcc -Wall -ansi -pedantic
and in fact produce identical executables.
What is the story with function pointers? Is it good style to
dereference them to call them? Gcc doesn't even complain about return
(**f)(0); !
I would have guessed that since I can write f= fn; that f and fn have the
same type, but then Gcc doesn't complain about f= & fn; either, which
makes more sense when you look at the typedef.
So should I write f= fn or f= &fn, and should I write f(0); or (*f)(0);
The former in each case is what you would do if functions were like an
array type, and the latter makes sense if pointers were like scalars.
Surely the standard can't permit both - that seems quite sloppy.
Thanks,
viza
I have program1.c:
typedef int (*fn_t)(int);
int fn( int f ){
return f;
}
int main( void ){
fn_t f= fn;
return f( 0 );
}
and program2.c
typedef int (*fn_t)(int);
int fn( int f ){
return f;
}
int main( void ){
fn_t f= fn;
return (*f)( 0 );
}
They both compile with no errors/warnings/comments under
gcc -Wall -ansi -pedantic
and in fact produce identical executables.
What is the story with function pointers? Is it good style to
dereference them to call them? Gcc doesn't even complain about return
(**f)(0); !
I would have guessed that since I can write f= fn; that f and fn have the
same type, but then Gcc doesn't complain about f= & fn; either, which
makes more sense when you look at the typedef.
So should I write f= fn or f= &fn, and should I write f(0); or (*f)(0);
The former in each case is what you would do if functions were like an
array type, and the latter makes sense if pointers were like scalars.
Surely the standard can't permit both - that seems quite sloppy.
Thanks,
viza