Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 220
 2012 Microchip Technology Inc.
Specifying the time option to the #pragma switch directive forces the compiler to 
generate a table look-up style switch method. The time taken to execute each case 
is the same, so this is useful where timing is an issue, e.g state machines.
This pragma affects all subsequent code.
The auto option may be used to revert to the default behavior.
There is information printed in the assembly list file for each switch statement show-
ing the chosen strategy, see Section 6.6.4 “Switch Statement Information”.
5.14.4.11 THE #PRAGMA WARNING DIRECTIVE
This pragma allows control over some of the compiler’s messages, such as warnings 
and errors. For full information on the massaging system employed by the compiler, 
see Section 4.6 “Compiler Messages”.
5.14.4.11.1 The Warning Disable Pragma
Some warning messages can be disabled by using the warning disable pragma.
This pragma will only affect warnings that are produced by the parser or the code gen-
erator; i.e., errors directly associated with C code. The position of the pragma is only 
significant for the parser; i.e., a parser warning number may be disabled for one section 
of the code to target specific instances of the warning. Specific instances of a warning 
produced by the code generator cannot be individually controlled and the pragma will 
remain in force during compilation of the entire module.
The state of those warnings which have been disabled can preserved and recalled 
using the warning push and warning pop pragmas. Pushes and pops can be 
nested to allow a large degree of control over the message behavior.
The following example shows the warning associated with assigning the address of a 
const
 object to a pointer to non-const objects. Such code normally produces warning 
number 359.
int readp(int * ip) {
    return *ip;
}
const int i = 'd';
void main(void) {
    unsigned char c;
#pragma warning disable 359
    readp(&i);
#pragma warning enable 359
}
This same affect would be observed using the following code.
#pragma warning push
#pragma warning disable 359
    readp(&i);
#pragma warning pop
Here the state of the messaging system is saved by the warning push pragma. 
Warning 359 is disabled, then after the source code which triggers the warning, the 
state of the messaging system is retrieved by using the warning pop pragma.