The semantics introduced in C99 are a bit confusing, I must admit. The inline
coefficient allows you to define alternative function definitions.
If a function is defined everywhere as inline
both in declarations and in a definition, this definition is valid only in the local translation unit. In the C99 standard, this definition is very vague, but in practice most compilers implement this in a similar way to static inline
. Essentially, just inline
overwrites any other function with the same name in any other binding node. Thus, if you declare the function as soon as inline
in the header, the compiler will wait for its definition in one compilation unit and will later give you an error if this is not so.
Now, if a function should be both built-in and available in other translation units, it should be defined as extern
in the header declaration. Then the compiler will not search for it only in the current compilation unit.
static inline
by far the most portable definition at the moment and is limited to the current translation unit. This is often found in headers along with the actual definition of a function.
source share