Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル
製品コード
SW006021-1
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 182
2012 Microchip Technology Inc.
5.8
FUNCTIONS
Functions may be written in the usual way in accordance with the C language. Imple-
mentation and special features associated with functions are discussed in the following
sections.
mentation and special features associated with functions are discussed in the following
sections.
5.8.1
Function Specifiers
Functions may, in the usual way, use the standard specifier static. A function defined
using the static specifier only affects the scope of the function; i.e., limits the places
in the source code where the function may be called. Functions that are static may
only be directly called from code in the file in which the function is defined. The equiv-
alent symbol used in assembly code to represent the function may change it the func-
tion is static, see 5.12.3 “Interaction Between Assembly and C Code”. This
specifier does not change the way the function is encoded.
using the static specifier only affects the scope of the function; i.e., limits the places
in the source code where the function may be called. Functions that are static may
only be directly called from code in the file in which the function is defined. The equiv-
alent symbol used in assembly code to represent the function may change it the func-
tion is static, see 5.12.3 “Interaction Between Assembly and C Code”. This
specifier does not change the way the function is encoded.
Non-standard qualifiers are discussed below.
5.8.1.1
INTERRUPT SPECIFIER
The interrupt specifier indicates that the function is an interrupt service routine and
that it is to be encoded specially to suit this task. Interrupt functions are described in
detail in 5.9.1 “Writing an Interrupt Service Routine”.
that it is to be encoded specially to suit this task. Interrupt functions are described in
detail in 5.9.1 “Writing an Interrupt Service Routine”.
5.8.1.2
INLINE SPECIFIER
The inline function specifier is a recommendation that calls to the specified function
be as fast as possible. The compiler may be able to inline the body of the function spec-
ified if certain conditions are met.
be as fast as possible. The compiler may be able to inline the body of the function spec-
ified if certain conditions are met.
The following is an example of a function which has been made a candidate for inlining.
inline int combine(int x, int y) {
return 2*x-y;
}
All function calls to any function that was inlined by the compiler will be encoded as if
the call was replaced with the body of the called function. This is performed at the
assembly code level, Inlining will only take place if the assembly optimizers are
enabled. The function itself may still be encoded by the compiler even if it is inlined.
the call was replaced with the body of the called function. This is performed at the
assembly code level, Inlining will only take place if the assembly optimizers are
enabled. The function itself may still be encoded by the compiler even if it is inlined.
If inlining takes place, this will increase the program’s execution speed, since the call
and return sequences associated with the call will be eliminated. It will also reduce the
hardware stack usage as no call instruction is actually executed. Any stack reduction
is not reflected in the call graphs shown in the assembly list file as this file is generated
before inlining takes place.
and return sequences associated with the call will be eliminated. It will also reduce the
hardware stack usage as no call instruction is actually executed. Any stack reduction
is not reflected in the call graphs shown in the assembly list file as this file is generated
before inlining takes place.
If inlining takes place, code size may be reduced if the assembly code associated with
the body of the inlined function is very small and the function itself is not output. Code
size will increase if the body of the inlined function is larger than the call/return
sequence it replaces and that function is called more than once. You should only con-
sider this specifier for functions which generate small amounts of assembly code. Note
that the amount of C code in the body of a function is not a good indicator of the size
of the assembly code which it generates (see Section 3.6.13 “How Can I Tell How
Big a Function Is?”).
the body of the inlined function is very small and the function itself is not output. Code
size will increase if the body of the inlined function is larger than the call/return
sequence it replaces and that function is called more than once. You should only con-
sider this specifier for functions which generate small amounts of assembly code. Note
that the amount of C code in the body of a function is not a good indicator of the size
of the assembly code which it generates (see Section 3.6.13 “How Can I Tell How
Big a Function Is?”).
A function may not be inlined if it itself contains inline assembly. If the assembly for the
function contains certain assembly sequences, this may also prevent inlining of the
function. A warning will be generated if the function references static objects, to
comply with the ANSI Standard. A warning is also issued if it is not inlined successfully.
Your code should not make any assumption about whether inlining was successful and
which assembly code associated with the function is being executed.
function contains certain assembly sequences, this may also prevent inlining of the
function. A warning will be generated if the function references static objects, to
comply with the ANSI Standard. A warning is also issued if it is not inlined successfully.
Your code should not make any assumption about whether inlining was successful and
which assembly code associated with the function is being executed.