next up previous contents index
Next: 3.20 Defines Created by Up: 3. Using SDCC Previous: 3.18.2 DS390 Memory Model   Contents   Index


3.19 Pragmas

Pragmas are used to turn on and/or off certain compiler options. Some of them are closely related to corresponding command-line options (see section sec:Command-Line-Options).
Pragmas should be placed before and/or after a function, placing pragmas inside a function body could have unpredictable results.

SDCC supports the following #pragma directives:

The preprocessor SDCPP supports the following #pragma directives:

#pragma pedantic_parse_number + 
 
#define LO_B(x) ((x) & 0xff) 
 
unsigned char foo(void) 
{ 
   unsigned char c=0xfe-LO_B(3); 
 
   return c; 
} 

#pragma preproc_asm - 
#define MYDELAY _asm 
   nop ;my assembly comment... 
   nop 
   nop 
_endasm 
#pragma preproc_asm + 
 
void foo (void)  
{  
    ...  
    MYDELAY; 
    ...  
}  

#pragma preproc_asm + 
#pragma sdcc_hash + 
 
#define ROMCALL(x) \ 
   mov R6_B3, #(x & 0xff) \ 
   mov R7_B3, #((x >> 8) & 0xff) \ 
   lcall __romcall 
 
... 
_asm 
ROMCALL(72) 
_endasm; 
... 

Some of the pragmas are intended to be used to turn-on or off certain optimizations which might cause the compiler to generate extra stack and/or data space to store compiler generated temporary variables. This usually happens in large functions. Pragma directives should be used as shown in the following example, they are used to control options and optimizations for a given function.

#pragma save       /* save the current settings */  
#pragma nogcse     /* turnoff global subexpression elimination */  
#pragma noinduction /* turn off induction optimizations */  
int foo ()  
{  
   ...  
   /* large code */  
   ...  
}  
#pragma restore /* turn the optimizations back on */
The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the save and restore pragmas be used when changing options for a function.



next up previous contents index
Next: 3.20 Defines Created by Up: 3. Using SDCC Previous: 3.18.2 DS390 Memory Model   Contents   Index
2008-12-05