What does 'sizeof (function name)' return?

Pointer picture Pointer · Apr 19, 2010 · Viewed 7.3k times · Source

Sample code:

int main(void)
{
    printf ("size = %d\n", sizeof(main));
}

What is the returned value sizeof applied to a function name, for example main?

Answer

qrdl picture qrdl · Apr 19, 2010

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.