How can you calculate size of a function? There is nothing like size of function. Size of function may include the number of lines in the code. Logic complexity of the function. Size of function can not be calculated in terms of using sizeof function.
Above answer was rated as good by the following members: yzesong
How can you calculate size of a function? There is nothing like size of function. Size of function may include the number of lines in the code. Logic complexity of the function. Size of function can not be calculated in terms of using sizeof function.
I tried on sun4u sparc SUNW Sun-Fire-V440 machine and i got size of function as 4 bytes. I used sizeof function itself to determine the size of the empty function.
Pradeep You are absolutely wrong. sizeof() library function will find the size of function also. Try below code .. #include<iostream> typedef struct A { int a; float b; long c; }A1;
A1 a() { int a;int b; a 12;b 13;b a+b; }
int main() { cout<<sizeof(a())<<endl; return 0; }
Now your second & third points are not valid why because here sizeof function always give the return type of function.
It might be helpful to what exactly happens in line:
cout<<sizeof(a())<<endl;
This line actually makes a call to the function a. Put a cout statement inside the function body and you'll see the proof.
So to re-iterate it's meaningless to speak of the size of a function. However it does make sense to speak about the size of an address of a function. Tha size varies depending on the machine architecture and will typically be either 4 or 8 for 32 and 64 bit architectures respectively.