Is there any difference when compilers implements C inline function in different platforms

StackOverflow https://stackoverflow.com/questions/23257384

  •  08-07-2023
  •  | 
  •  

Domanda

I was told that the implementation for C inline functions in different platforms (e.g. Mips vs x86) is a little different. For example, inline function for one of them (Mips or x86) still allocates stack and thus not so efficient. Is it true? What are all the difference? Thanks

È stato utile?

Soluzione

It is not guaranteed that every function will be inlined when you declare it inline (it is just a suggestion to the compiler). Hence for any architecture the functions that aren't inlined will be treated as normal functions, and hence the push & pop from the stack when you call them (like any normal non-inlined function)

And it is pretty much dependent upon how your compiler is configured. For eg, GCC has flags like:

-finline-functions
Consider all functions for inlining, even if they are not declared inline. The compiler heuristically decides which functions are worth integrating in this way.

-finline-limit=n
By default, GCC limits the size of functions that can be inlined. This flag allows coarse control of this limit. n is the size of functions that can be inlined in number of pseudo instructions.

--param name=value
In some places, GCC uses various constants to control the amount of optimization that is done. For example, GCC does not inline functions that contain more than a certain number of instructions. You can control some of these constants on the command line using the --param option.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top