C Preprocessor srcML Language Documentation

C Preprocessor XML Element Subelements

#define

<cpp:define>

<cpp:directive>, <cpp:macro>, <cpp:value>

#undef

<cpp:undef>

<cpp:directive>, <name>

#if

<cpp:if>

<cpp:directive>, <expr>

#ifdef

<cpp:ifdef>

<cpp:directive>, <expr>

#ifndef

<cpp:ifndef>

<cpp:directive>, <expr>

#else

<cpp:else>

<cpp:directive>

#elif

<cpp:elif>

<cpp:directive>, <expr>

#endif

<cpp:if>

<cpp:directive>

#include

<cpp:include>

<cpp:directive>, <cpp:file>

#pragma

<cpp:pragma>

<cpp:directive>

#error

<cpp:error>

<cpp:directive>

#warning

<cpp:warning>

<cpp:directive>

#line

<cpp:line>

<cpp:directive>, <cpp:number>, <cpp:file>

#

<cpp:empty>

#define


Element

Subelements

XPath Queries

  • uses of #define

    //cpp:define
  • macro definitions of a macro with the name LENGTH

    //cpp:define[cpp:macro/src:name[. = 'LENGTH']]
  • macro-definition values

    //cpp:define/cpp:value
  • macro definitions with parameters

    //cpp:define[src:parameter_list]
  • macro-declaration parameter names

    //cpp:define/src:parameter_list/src:parameter
  • variadic macro definitions

    //cpp:define[src:parameter_list[ .//src:modifier = '...']]

Examples

trivial #define

#define WIDTH 80
#define LENGTH ( WIDTH + 10 )
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>WIDTH</name></cpp:macro> <cpp:value>80</cpp:value></cpp:define>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>LENGTH</name></cpp:macro> <cpp:value>( WIDTH + 10 )</cpp:value></cpp:define>

#define used like a function

#define multiply( f1, f2 ) ( f1 * f2 )
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>multiply</name><parameter_list>( <parameter><type><name>f1</name></type></parameter>, <parameter><type><name>f2</name></type></parameter> )</parameter_list></cpp:macro> <cpp:value>( f1 * f2 )</cpp:value></cpp:define>

#define a variadic macro

#define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>eprintf</name><parameter_list>(<parameter><type><name>format</name></type></parameter>, <parameter><type><modifier>...</modifier></type></parameter>)</parameter_list></cpp:macro> <cpp:value>fprintf (stderr, format, __VA_ARGS__)</cpp:value></cpp:define>

#undef


Element

Subelements

XPath Queries

  • uses of #undef

    //cpp:undef
  • names of undefined macros

    //cpp:undef/src:name
  • macro names which are both defined and undefined

    //cpp:undef/src:name[.= //cpp:define/src:macro/src:name]

Example

#define multiply( f1, f2 ) ( f1 * f2 )
#undef multiply
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>multiply</name><parameter_list>( <parameter><type><name>f1</name></type></parameter>, <parameter><type><name>f2</name></type></parameter> )</parameter_list></cpp:macro> <cpp:value>( f1 * f2 )</cpp:value></cpp:define>
<cpp:undef>#<cpp:directive>undef</cpp:directive> <name>multiply</name></cpp:undef>

#if


Element

Subelements

XPath Queries

  • uses of #if

    //cpp:if
  • conditions used by #if

    //cpp:if/src:expr

Example

#if DLEVEL > 5
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><name>DLEVEL</name> <operator>&gt;</operator> <literal type="number">5</literal></expr></cpp:if>

#endif


Element

Subelement

XPath Query

  • uses of #endif

    //cpp:endif

Example

#endif
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>

#include


Element

Subelements

XPath Queries

  • includes

    //cpp:include
  • includes that use quotes

    //cpp:include[cpp:file/src:literal[-type ='string']]
  • Names of all included files

    //cpp:include/cpp:file

Example

#include <FileName>
#include "fileName"
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file>&lt;FileName&gt;</cpp:file></cpp:include>
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file>"fileName"</cpp:file></cpp:include>

#pragma


Element

Subelement

XPath Query

  • uses of #pragma

    //cpp:pragma

Example

// #pragma example
#pragma warning( once : 4385 )
#pragma ms_struct on
<comment type="line">// #pragma example</comment>
<cpp:pragma>#<cpp:directive>pragma</cpp:directive> <name>warning</name><name>(</name> <name>once</name> <name>:</name> <name>4385</name> <name>)</name></cpp:pragma>
<cpp:pragma>#<cpp:directive>pragma</cpp:directive> <name>ms_struct</name> <name>on</name></cpp:pragma>

#error


Element

Subelement

XPath Query

  • uses of #error

    //cpp:error

Example

// #error message example
#if !defined(__cplusplus)
#error "C++ compiler required."
#endif
<comment type="line">// #error message example</comment>
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><operator>!</operator><call><name>defined</name><argument_list>(<argument><expr><name>__cplusplus</name></expr></argument>)</argument_list></call></expr></cpp:if>
<cpp:error>#<cpp:directive>error</cpp:directive> <cpp:literal>"C++ compiler required."</cpp:literal></cpp:error>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>

#warning


Element

Subelement

XPath Query

  • uses of #warning

    //cpp:warning

Example

#warning "Feature not yet supported"
<cpp:warning>#<cpp:directive>warning</cpp:directive> <cpp:literal>"Feature not yet supported"</cpp:literal></cpp:warning>

#line


Element

Subelements

XPath Queries

  • uses of #line

    //cpp:line
  • line numbers used by #line directives

    //cpp:line/cpp:number/src:literal
  • #line directives which reference the file “copy.c”

    //cpp:line[cpp:file/src:literal = '"copy.c"']

Example

// #line directive example
#line 151 "copy.c"
<comment type="line">// #line directive example</comment>
<cpp:line>#<cpp:directive>line</cpp:directive> <cpp:number>151</cpp:number> <cpp:file>"copy.c"</cpp:file></cpp:line>

#


Element

XPath Query

  • blank preprocessor lines

    //cpp:empty

Example

#
<cpp:empty>#</cpp:empty>