Microchip Technology SW006021-2 ユーザーズマニュアル
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 216
2012 Microchip Technology Inc.
5.14.4.7
THE #PRAGMA PRINTF_CHECK DIRECTIVE
Certain library functions accept a format string followed by a variable number of argu-
ments in the manner of printf(). Although the format string is interpreted at runtime,
it can be compile-time checked for consistency with the remaining arguments.
ments in the manner of printf(). Although the format string is interpreted at runtime,
it can be compile-time checked for consistency with the remaining arguments.
This directive enables this checking for the named function, for example the system
header file <stdio.h> includes the directive:
header file <stdio.h> includes the directive:
#pragma printf_check(printf) const
to enable this checking for printf(). You may also use this for any user-defined
function that accepts printf -style format strings.
function that accepts printf -style format strings.
The qualifier following the function name is to allow automatic conversion of pointers in
variable argument lists. The above example would cast any pointers to strings in RAM
to be pointers of the type (const char *)
variable argument lists. The above example would cast any pointers to strings in RAM
to be pointers of the type (const char *)
Note that the warning level must be set to -1 or below for this option to have any visible
effect. See Section 4.8.59 “--WARN: Set Warning Level”.
effect. See Section 4.8.59 “--WARN: Set Warning Level”.
5.14.4.8
THE #PRAGMA PSECT DIRECTIVE
Normally the object code generated by the compiler is broken into the standard psects.
This is described in 5.15.2 “Compiler-Generated Psects”. For an introductory guide
to psects, see Section 5.15.1 “Program Sections”. This is fine for most applications,
but sometimes it is necessary to redirect variables or code into different psects when a
special memory configuration is desired.
This is described in 5.15.2 “Compiler-Generated Psects”. For an introductory guide
to psects, see Section 5.15.1 “Program Sections”. This is fine for most applications,
but sometimes it is necessary to redirect variables or code into different psects when a
special memory configuration is desired.
Some code and data compiler-generated psects may be redirected using a #pragma
psect
psect
directive. The general form of this pragma looks like:
#pragma psect standardPsect=newPsect
and instructs the code generator that anything that would normally appear in the stan-
dard psect standardPsect, will now appear in a new psect called newPsect. This
psect will be identical to standardPsect in terms of its flags and attributes; however,
it will have a unique name. Thus, you can explicitly position this new psect without
affecting the placement of anything in the original psect.
dard psect standardPsect, will now appear in a new psect called newPsect. This
psect will be identical to standardPsect in terms of its flags and attributes; however,
it will have a unique name. Thus, you can explicitly position this new psect without
affecting the placement of anything in the original psect.
If the name of the standard psect that is being redirected contains a counter (e.g.,
text0
text0
, text1, text2, etc.), the placeholder %%u should be used in the name of the
psect at the position of the counter, e.g., text%%u. This will match any psect, regard-
less of the counter value. For example, to remap a C function, you could use:
less of the counter value. For example, to remap a C function, you could use:
#pragma psect text%%u=lookupfunc
int lookup(char ind)
{
...
Standard psects that make reference to a bank number are not using a counter and do
not need the placeholder to match. For example, the redirect an uninitialized variable
from bank 1 memory, use:
not need the placeholder to match. For example, the redirect an uninitialized variable
from bank 1 memory, use:
#pragma psect bssBANK1=sharedObj
int foobar;
This pragma should not be used for any of the data psects (data or idata) that hold
initialized variables. These psects must be assembled in a particular order and the use
of this pragma to redirect some of their content will destroy this order. Use of this
pragma with RAM-based psects that are intended to be linked into a particular RAM
bank is acceptable, but the new psect must be linked into the same bank. Linking the
new psect to a different bank may lead to code failure.
initialized variables. These psects must be assembled in a particular order and the use
of this pragma to redirect some of their content will destroy this order. Use of this
pragma with RAM-based psects that are intended to be linked into a particular RAM
bank is acceptable, but the new psect must be linked into the same bank. Linking the
new psect to a different bank may lead to code failure.