SPRU514Y August 2001 – June 2022
When declaring a function in a header file as static inline, you must follow additional procedures to avoid a potential code size increase in case the optimizer is not run.
To prevent a static inline function in a header file from causing an increase in code size when inlining gets turned off, use the following procedure. This allows external-linkage when inlining is turned off; thus, only one function definition will exist throughout the object files.
In the following examples there are two definitions of the strlen function. The first (Section 3.12.4.1), in the header file, is an inline definition. This definition is enabled and the prototype is declared as static inline only if _INLINE is true (_INLINE is automatically defined for you when the optimizer is used ).
The second definition (see Section 3.12.4.2) for the library, ensures that the callable version of strlen exists when inlining is disabled. Since this is not an inline function, the _INLINE preprocessor symbol is undefined (#undef) before string.h is included to generate a non-inline version of strlen's prototype.