Question

Lets say i have two inline functions in my header file:

inline int foo() { return bar()+2; }
inline int bar() { return 3; }

can i assume that a C99 compiler will inline "foo" even if 'bar' is declared later? Assuming that no other internal rule like function body to large is triggered.

Are implementations of c compilers doing this (popular ones say Intel-C/Sun Studio/MSVC and gcc) even if C99 leave this as an option?

Was it helpful?

Solution

As long as the functions are properly prototyped, it's not going to matter what order you declare them in.

OTHER TIPS

inline is just a hint to the compiler, and more often than not it's ignored in modern optimizing compilers. You cannot assume anything about whether something gets inlined or not. Some compilers provide pragmas that force a particular function to be inlined if it is at all possible (e.g. MSVC __forceinline). If you absolutely need to know, you have to look at the disassembly of the output.

That said, for a given snippet, any decent optimizing compiler would inline that, with inline or without, so long as it's a single header.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top