Ian Collins said:
*Please don't quote signatures.*
Constraint violation, see 6.5.3.4.1
"The sizeof operator shall not be applied to an expression that has
function type..."
Did this even compile?
Quite possibly it does; gcc accepts 'sizeof(main)' (as an extension)
by default.
To the original poster: if you invoke gc with "-std=c99 -pedantic", it
will complain about several problems in your program. If you replace
"-std=99" with "-ansi", it will also complain about the "//" comments
(actually it will completely fail to recognize them and complain about
syntax errors).
Using "//" comments in Usenet postings is usually a bad idea; wrapping
of long lines can easily introduce syntax errors. And you've
neglected the #include directives for <stdio.h> (needed for printf)
and <stdlib.h> (needed for system). And you attempt to use the "%d"
format for arguments of type size_t and of pointer types.
Here's a *nearly* correct version of your program:
#include <stdio.h>
#include <stdlib.h>
typedef int (*Fn)(void);
int main( void ) {
Fn fn = main;
printf("%d\n", (int)sizeof(fn));
printf("%d\n", (int)sizeof(&fn));
printf("%d\n", (int)sizeof(&main));
/* printf("%d\n", (int)sizeof(main)); */
printf("%p %p\n", (void*)fn, (void*)&fn);
printf("%p %p\n", (void*)main, (void*)&main);
return 0;
}
I wrote "nearly" because the casts on the last two printf statements
are actually illegal. There is no portable way to print the value of
a pointer-to-function (other than by decomposing it into a sequence of
bytes). Allowing conversion to void* is a common extension -- more
common, I think, than allowing sizeof to be applied to functions.