Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Is it possible to determine the size of the function using the sizeof operator?

0
Posted

Is it possible to determine the size of the function using the sizeof operator?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123