xHarbour Reference Documentation > Preprocessor Reference xHarbour Developers Network  

#pragma

Controls compiler switches at compile time.

Syntax

#pragma <keyword> = ON|OFF
#pragma /<switch>    +|-

#pragma push /<switch>  +|-
#pragma pop  /<switch>

Arguments

<keyword>
This is the keyword identifying the compiler option to switch ON or OFF.
<switch>
As an alternative, the compiler switch can be specified in abbreviated notation followed by a plus sign (ON) or minus sign (OFF).
push
Pushes a new pragma on top of the stack.
pop
Removes the last pragma from the top of the stack.

Description

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
KeywordsSwitchesDescription
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.

Info

See also:#error, #stdout
Category: Preprocessor directives , xHarbour extensions

Examples

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe