5.14.3.10 The #pragma Switch Directive
Normally, the compiler encodes switch
statements to
produce the smallest possible code size. The #pragma switch
directive can
be used to force the compiler to use a different coding strategy.
The switch pragma affects all subsequent code and has the general form:
#pragma switch switchType
where switchType
is one of the available
selections that are listed in the Table 5-18 tables. The only switch type currently implemented for PIC18 devices is space.
Switch Type | Description |
---|---|
speed |
Use the fastest switch method. |
space |
Use the smallest code size method. |
time |
Use a fixed delay switch method. |
auto |
Use smallest code size method (default). |
direct (deprecated) |
Use a fixed delay switch method. |
simple (deprecated) |
Sequential xor method. |
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., with state machines.
The auto
option can be used to revert to the default
behavior.
Information is printed in the assembly list file for each
switch
statement, showing the chosen strategy (see 6.3.4 Switch Statement Information).