D
David Scarlett
Can anyone tell me whether the following is legal C?
int foo(int);
int bar(int (*)(int));
int main(void)
{
int x;
x = bar(&foo);
return 0;
}
int bar(int (*foo)(int))
{
/* ... */
}
I had some similar code which compiled fine using 'gcc -Wall', but I'm
concerned about what would happen if I called 'foo' from withing 'bar'.
Would it use the pointer it is passed, or the function declared at the
start, if they were different functions? Or is this undefined
behaviour? What if I used the dereferencing operator when calling foo?
I've changed the name of the pointer 'bar' recieves just to be safe,
but I'm still curious as to what the effects of this sort of code would
be...
Thanks.
int foo(int);
int bar(int (*)(int));
int main(void)
{
int x;
x = bar(&foo);
return 0;
}
int bar(int (*foo)(int))
{
/* ... */
}
I had some similar code which compiled fine using 'gcc -Wall', but I'm
concerned about what would happen if I called 'foo' from withing 'bar'.
Would it use the pointer it is passed, or the function declared at the
start, if they were different functions? Or is this undefined
behaviour? What if I used the dereferencing operator when calling foo?
I've changed the name of the pointer 'bar' recieves just to be safe,
but I'm still curious as to what the effects of this sort of code would
be...
Thanks.