top | item 47025934

(no title)

garaetjjte | 14 days ago

>In the latter case, even when the compiler chooses to inline the function, it also emits code for an independent instance of the function, because the function is public and it may be called from another file.

Not in standard C. "inline" function provides implementation for usage iff compiler decides to inline the call. If it does decide not to inline, it will emit call to external symbol that needs to be defined in different TU (otherwise you will get errors at link time).

discuss

order

adrian_b|14 days ago

The meaning of "inline" differs between C and C++.

Quote from the gcc manual:

"GCC implements three different semantics of declaring a function inline. One is available with -std=gnu89 or -fgnu89-inline or when gnu_inline attribute is present on all inline declarations, another when -std=c99, -std=gnu99 or an option for a later C version is used (without -fgnu89-inline), and the third is used when compiling C++."

Nevertheless, "static inline" means the same thing in all 3 standards, unlike "inline" alone.

This can be a reason to always prefer "static inline", because then it does not matter whether the program is compiled as C or as C++.