ISO C++ does not have a notion of the size of a function.
How the compiler creates the machine-level instructions for the individual functions and merges them into an entire program is not specified by the ISO standard. Every individual platform can do this its own way. Therefore, it would not make sense for the ISO standard to attempt to define what the size of a function is.
As a consequence, you cannot use the sizeof
operator to determine the size of a function.
When you write the expression &test
, you get a pointer that points to the function test
. On 32-bit platforms, pointers are usually 32 bits (i.e. 4 bytes), and on 64-bit platforms, they are usually 64 bits (i.e. 8 bytes).
That is why the expressions
sizeof(&test)
and
sizeof(&test1)
will both evaluate to either 4
or 8
, depending on your platform.
Depending on how code is generated on your platform, you may be able to find a meaningful definition of the size of a function, and find the size of a function in a platform-specific manner. However, most platforms perform compiler optimizations which allow functions to be, for example, inlined, so that they may not even exist as a separate entity. In such a case, it is probably hard to find a meaningful definition of the size of a function.