Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'sizeof (function name)' return?

Tags:

c

function

sizeof

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?

like image 426
Pointer Avatar asked Apr 19 '10 09:04

Pointer


People also ask

What is the return of sizeof function?

The function returns int , so it's sizeof(int) , which, on 32 bit systems is typically 4 bytes.

What does sizeof function return in C++?

The sizeof() operator is a function which returns the size of any data type, expression, array, etc. It takes the data type or expression as a part of argument which is mandatory and returns the result which is size of that data type in bytes. If it is an array it will return the number of elements present in it.

What units does sizeof return?

Answer: sizeof returns the size of the type in bytes.

What is the use of sizeof () function in C?

What is the sizeof() function in C? The sizeof() function in C is a built-in function that is used to calculate the size (in bytes)that a data type occupies in ​the computer's memory.


1 Answers

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.

like image 150
qrdl Avatar answered Oct 06 '22 02:10

qrdl