M
MK
Hello,
I have been trying to get a handle on the following piece of code.
----- BEGIN ----
#include <stdio.h>
int
f2args(int a,int b)
{
printf("a=%d,b=%d\n",a,b);
return 1;
}
typedef int (*func3args)(int,int,int);
int
main(int argc,char **argv)
{
func3args fp = (func3args)f;
fp(1,2,3);
exit(0);
}
----- END ----
weird things:
- I get no compiler warnings or errors (porbably because I used a cast
(func)).
- And when I run I expect the program to crash, but it runs fine.
$ ./a.out
a=1,b=2
My questions are:
- Is this portable and guranteed by the C standard?
- Or is it the manifestation of the C calling convention (the
default), hence not portable or
implementation dependent.
I dug aroung and saw a lot of information regarding 'function pointer
compatibility', I guess I
don't fully understand that.
Thanks
MK
I have been trying to get a handle on the following piece of code.
----- BEGIN ----
#include <stdio.h>
int
f2args(int a,int b)
{
printf("a=%d,b=%d\n",a,b);
return 1;
}
typedef int (*func3args)(int,int,int);
int
main(int argc,char **argv)
{
func3args fp = (func3args)f;
fp(1,2,3);
exit(0);
}
----- END ----
weird things:
- I get no compiler warnings or errors (porbably because I used a cast
(func)).
- And when I run I expect the program to crash, but it runs fine.
$ ./a.out
a=1,b=2
My questions are:
- Is this portable and guranteed by the C standard?
- Or is it the manifestation of the C calling convention (the
default), hence not portable or
implementation dependent.
I dug aroung and saw a lot of information regarding 'function pointer
compatibility', I guess I
don't fully understand that.
Thanks
MK