xHarbour Reference Documentation > Preprocessor Reference |
Controls compiler switches at compile time.
#pragma <keyword> = ON|OFF #pragma /<switch> +|- #pragma push /<switch> +|- #pragma pop /<switch>
The #pragma directive is the only one processed by the compiler instead of the preprocessor. #pragma allows for changing compiler options while a PRG file is being compiled. It becomes possible to change a compiler switch for a single line of source code and set it back to its original value when that line is processed. The directive supports the following pragmas:
xHarbour pragmas
Keywords | Switches | Description |
---|---|---|
AUTOMEMVARS = On|Off | /A +|- | automatic memvar declaration |
DEBUGINFO = On|Off | /B +|- | include debug info |
ENABLEWARNINGS = On|Off | /W +|- | enable warnings |
EXITSEVERITY = nLevel | /E<nLevel> | set exit severity |
FORCEMEMVARS = On|Off | /V +|- | variables are assumed M-> |
LINEINFO = On|Off | /L +|- | suppress line number information |
NOSTARTPROC = On|Off | /N +|- | no implicit starting procedure |
PREPROCESSING = On|Off | /P +|- | generate pre-processed output (.ppo) file |
WARNINGLEVEL = nLevel | /W<nLevel> | sets warning level |
SHORTCUTTING = On|Off | /Z +|- | supress shortcutting |
TRACEPRAGMAS = On|Off | trace pragma settings |
Note: there is no switch notation for the TRACEPRAGMAS pragma.
See also: | #error, #stdout |
Category: | Preprocessor directives , xHarbour extensions |
// The example demonstrates the result of pragmas using two // identical IF statements. The first IF statement generates a // warning and leaves the variable c2 unassigned due to shortcut // optimization. The second IF statement generates no warning and // assigns a value to c2 since warning and shortcut optimization // are both switched off. #pragma TRACEPRAGMAS = ON #pragma ENABLEWARNINGS = ON PROCEDURE Main LOCAL c1 := "A" IF IsAlpha( c1 ) .OR. ; IsDigit( c2 := "2" ) // Warning: Ambiguous referece C2 ? c1, Type( "c2" ) // result: A U ENDIF #pragma /Z- #pragma /W- IF IsAlpha( c1 ) .OR. ; IsDigit( c2 := "2" ) // No Warning ? c1, Type( "c2" ) // result: A C ENDIF RETURN
// The example is identical to the above, but uses #pragma push/pop PROCEDURE Main LOCAL c1 := "A" #pragma push /w3 // Switch warning level 3 on IF IsAlpha( c1 ) .OR. ; IsDigit( c2 := "2" ) // Warning: Ambiguous referece C2 ? c1, Type( "c2" ) // result: A U ENDIF #pragma pop /w // Switch warning level off #pragma push /z+ // Switch shortcut optimization off IF IsAlpha( c1 ) .OR. ; IsDigit( c2 := "2" ) // No Warning ? c1, Type( "c2" ) // result: A C ENDIF RETURN
http://www.xHarbour.com