Using Inline Function Expansion
2-32
2.6.4 The _INLINE Preprocessor Symbol
The _INLINE preprocessor symbol is defined (and set to 1) if you invoke the
parser (or compiler shell utility) with the
−
x2 (or
−
x) option. It allows you to write
code so that it runs whether or not the optimizer is used. It is used by standard
header files included with the compiler to control the declaration of standard
C run-time functions.
1 on page 2-33 illustrates how the run-time-support library uses
the _INLINE preprocessor symbol.
The _INLINE preprocessor symbol is used in the string.h header file to declare
the function correctly, regardless of whether inlining is used. The _INLINE pre-
processor symbol conditionally defines _ _INLINE so that strlen is declared
as static inline only if the _INLINE preprocessor symbol is defined.
If the rest of the modules are compiled with inlining enabled
and the string.h
header is included, all references to strlen are inlined and the linker does not
have to use the strlen in the run-time-support library to resolve any references.
Otherwise, the run-time-support library code resolves the references to strlen,
and function calls are generated.
Use the _INLINE preprocessor symbol in your header files in the same way
that the function libraries use it so that your programs run, regardless of
whether inlining is selected for any or all of the modules in your program.
Functions declared as inline are expanded whenever the optimizer is invoked
at any level. Functions declared as inline and controlled by the _INLINE
preprocessor symbol, such as the run-time-library functions, are expanded
whenever the optimizer is invoked and the _INLINE preprocessor symbol is
equal to 1. When you declare an inline function in a library, it is recommended
that you use the _INLINE preprocessor symbol to control its declaration. If you
fail to control the expansion using _INLINE and subsequently compile
without
the optimizer, the call to the function is unresolved.
In Example 2
1, there are two definitions of the strlen function. The first, in the
header file, is an inline definition. Note that this definition is enabled and the
prototype is declared as static inline only if _INLINE is true; that is, the module
including this header is compiled with the
−
x option.
The second definition, 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 gen-
erate a noninline version of strlen’s prototype.
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...