8.5 Implementation-Specific Preprocessor Directive (#pragma)

The #pragma directive is a standard method for implementing platform-dependent features. This directive has the following syntax:

#pragma pp-tokens(opt) newline

The supported pragmas vary across platforms. All unrecognized pragmas are diagnosed with an informational message. See your platform-specific DEC C documentation for a list of supported pragmas.

Some pragma directives are subject to macro expansion. A macro reference can occur anywhere after the keyword pragma . For example:

#define opt inline
#define f func
#pragma opt(f)

After both macros are expanded, the #pragma directive becomes #pragma inline (func) .

The following pragmas are subject to macro expansion:

builtins            inline                 linkage       standard
dictionary          noinline               module        nostandard
extern_model        member_alignment       message       use_linkage
extern_prefix       nomember_alignment

The following pragmas are also subject to macro expansion, primarily for use in preprocess-only mode (that is, with the /PREPROCESS_ ONLY qualifier on OpenVMS systems or the -E switch on Digital UNIX systems), and are not normally used when generating an object module with the DEC C compiler:


Note
Macro expansion is a feature of pragmas introduced in early versions of DEC C and is retained for backward compatibility. Pragmas added in more recent versions of the compiler and pragmas added in the future have changed that practice to conform to the defacto industry standard of not performing macro expansion. (ANSI C places no requirement on macro expansion of pragmas.)

The following describes how the compiler decides whether or not to macro-expand a given pragma:

In compilation modes other than /STANDARD=COMMON (OpenVMS systems) or -std0 (Digital UNIX systems), do Step 1:

Step 1:


The token following the keyword pragma is first checked to see if it is a currently-defined macro. If it is a macro and the identifier does not match the name of a pragma that is not subject to macro expansion, then just that macro (with its arguments, if function-like) is expanded. The tokens produced by that macro expansion are then processed along with the rest of the tokens on the line in Step 2.

In all compilation modes, do Step 2:

Step 2:


The first token following the keyword pragma is checked to see if it matches the name of a pragma that is subject to macro expansion. If it does, then macro expansion is applied to that token and to the rest of tokens on the line.

The test for matching a known pragma permits an optional double leading underscore. For example, #pragma __nostandard is equivalent to #pragma standard .

Example

The following example illustrates that for pragmas coded directly with a name that matches a known pragma, the macro-expansion behavior is generally the same in all modes and is backward- compatible. It is only in cases where a pragma was coded with a name that was not the name of a known pragma, expecting macro expansion to produce the pragma name, that backward-compatibility is broken, and then only in common mode. The exception is made in common mode to maintain compatibility with the Digital UNIX preprocessor.

  #define pointer_size error
  #define m1 e1
  #define e1 pointer_size 32
  #define standard message
  #define x disable(all)
  #define disable(y) enable(y)

  #pragma pointer_size 32  /* In common mode, Step 1 skipped.
                              In other modes, Step 1 finds that pointer_size
                                   is known not to expand.
                              In any mode, Step 2 finds pointer_size is
                                   not a pragma requiring expansion. */

  #pragma m1   /* In common mode, Step 1 skipped.
                  In other modes, Step 1 expands m1 to pointer_size 32.
                  In common mode, Step 2 finds m1 is not a pragma requiring
                         expansion.
                  In other modes, Step 2 finds pointer_size is not a pragma
                         requiring expansion. */

  #pragma standard x  /* In common mode, Step 1 skipped.
                         In other modes, Step 1 expands to message x.
                         In common mode, Step 2 expands to message enable(all).
                         In other modes, Step 2 expands message x to
                            message enable(all). */


Previous Page | Next Page | Table of Contents | Index