sample code:
main ()
{
printf ("size = %d\n", sizeof (main));
}
sample code:
main ()
{
printf ("size = %d\n", sizeof (main));
}
The size of the function pointer, which will be the same as the size of any other pointer on your host architecture. Note that, when you are referring to main() as main, you are referring to the address of main().
ISO C++ forbids applying sizeof
to an expression of function type.
ISO/IEC 14882 on C++ says (section 5.3.3):
"The size operator shall not be applied to an expression that has function or incomplete type,..."
The same hold for standard C (ISO/IEC 9899:1999) section 6.5.3.4:
"The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression that designates a bit-field member."
C standard forbids it - when compiled with gcc -pedantic
, it produces invalid application of ‘sizeof’ to a function type
warning.
However gcc
compiles it and returns 1
for sizeof(main)
, and it is not a size of function pointer.
It seems to be compiler-dependent.
dont use sizeof with fuction
sizeof +int,char,double,,,,
or
sizeof + number