Function pointer arguments
- From: Jonathan Green <jonathanfgreen@xxxxxxxxx>
- Date: Tue, 02 Oct 2007 01:21:30 -0000
I have some questions about the behavior of the code below.
#include <stdio.h>
void test(void *v);
int main(void)
{
int i=1;
int j=2;
void (*fp)();
fp = test;
(*fp)(&i, j);
test(&i);
return 0;
}
void test(void *v)
{
printf("address is %p\n", v);
return;
}
I compiled the code using gcc -Wall -ansi -pedantic. No warnings or
errors were issued.
1. Why was no error issued for the extra argument when using the
function pointer? If I put an extra argument when calling "test" in
the following line, an error is given. Thats what I would expect.
2. What's the behavior when running the code with the extra argument?
3. The compiler kind of worried me when it didn't give any warnings.
Now I'm not sure how function pointers are handled. Do I need a cast
when I correct the bad line and use (*fp)(&i) in the code above?
.
- Follow-Ups:
- Re: Function pointer arguments
- From: borophyll
- Re: Function pointer arguments
- From: Thomas Lumley
- Re: Function pointer arguments
- Prev by Date: sprintf and first argument
- Next by Date: Re: sprintf and first argument
- Previous by thread: sprintf and first argument
- Next by thread: Re: Function pointer arguments
- Index(es):
Relevant Pages
|
|