| Can I use sizeof to determine the exact size of functions?

Previous | The C Language |

Q: | Is it possible to determine the size of the function using the sizeof operator?
A: | No. In "normal" programs you should never know this information. ANSI C even does not propose what is `'sizeof(function)'`, and such construction will be rejected by the most of C compilers. GNU C (like TIGCC is) uses extended pointer arithmetic on such way that `'sizeof(function)'` is always 1. If you are a dirty hacker (as I am), and if you really need to determine the number of bytes occupied by function, I used the following method:
    void MyFunction(void)
    {
      // The function body...
    }
    void End_Marker(void);
    asm("End_Marker:");
    ...
    ...
    num_of_bytes = (char*)End_Marker - (char*)MyFunction;
Note however that this method is not absolutely reliable, because it depends of the ordering of functions in the program. But, the compiler is free to change the order of functions if such reorganization may lead to a better code.