156
Chapter 6. Extensions to the C Language Family
When a function is both inline and
, if all calls to the function are integrated into the caller, and
static
the function's address is never used, then the function's own assembler code is never referenced. In
this case, GCC does not actually output assembler code for the function, unless you specify the option
. Some calls cannot be integrated for various reasons (in particular,
-fkeep-inline-functions
calls that precede the function's definition cannot be integrated, and neither can recursive calls within
the definition). If there is a nonintegrated call, then the function is compiled to assembler code as
usual. The function must also be compiled as usual if the program refers to its address, because that
can't be inlined.
When an inline function is not
, then the compiler must assume that there may be calls from
static
other source files; since a global symbol can be defined only once in any program, the function must
not be defined in the other source files, so the calls therein cannot be integrated. Therefore, a non-
inline function is always compiled on its own in the usual fashion.
static
If you specify both
and
in the function definition, then the definition is used only for
inline
extern
inlining. In no case is the function compiled on its own, not even if you refer to its address explicitly.
Such an address becomes an external reference, as if you had only declared the function, and had not
defined it.
This combination of
and
has almost the effect of a macro. The way to use it is to
inline
extern
put a function definition in a header file with these keywords, and put another copy of the definition
(lacking
and
) in a library file. The definition in the header file will cause most calls
inline
extern
to the function to be inlined. If any uses of the function remain, they will refer to the single copy in
the library.
For future compatibility with when GCC implements ISO C99 semantics for inline functions, it is best
to use
only. (The existing semantics will remain available when
is
static inline
-std=gnu89
specified, but eventually the default will be
and that will implement the C99 semantics,
-std=gnu99
though it does not do so yet.)
GCC does not inline any functions when not optimizing unless you specify the
always_inline
attribute for the function, like this:
/* Prototype.
*/
inline void foo (const char) __attribute__((always_inline));
6.37. Assembler Instructions with C Expression Operands
In an assembler instruction using
, you can specify the operands of the instruction using C expres-
asm
sions. This means you need not guess which registers or memory locations will contain the data you
want to use.
You must specify an assembler instruction template much like what appears in a machine description,
plus an operand constraint string for each operand.
For example, here is how to use the 68881's
instruction:
fsinx
asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
Here
is the C expression for the input operand while
is that of the output operand. Each
angle
result
has
as its operand constraint, saying that a floating point register is required. The
in
indicates
"f"
=
=f
that the operand is an output; all output operands' constraints must use
. The constraints use the same
=
language used in the machine description (refer to Section 6.38 Constraints for
Operands).
asm
Each operand is described by an operand-constraint string followed by the C expression in parenthe-
ses. A colon separates the assembler template from the first output operand and another separates the
last output operand from the first input, if any. Commas separate the operands within each group. The
total number of operands is currently limited to 30; this limitation may be lifted in some future version
of GCC.
Need help?
Do you have a question about the ENTERPRISE LINUX 3 - USING GCC and is the answer not in the manual?
Questions and answers