srcML v1.0.0 C Preprocessor Documentation

C Preprocessor XML Element Subelements
# <cpp:empty>
#define <cpp:define> <cpp:directive> <cpp:macro> <cpp:value>
#elif <cpp:elif> <cpp:directive> <expr>
#else <cpp:else> <cpp:directive>
#endif <cpp:endif> <cpp:directive>
#error <cpp:error> <cpp:directive>
#if <cpp:if> <cpp:directive> <expr>
#ifdef <cpp:ifdef> <cpp:directive> <expr>
#ifndef <cpp:ifndef> <cpp:directive> <expr>
#include <cpp:include> <cpp:directive> <cpp:file>
#line <cpp:line> <cpp:directive> <cpp:number> <cpp:file>
#pragma <cpp:pragma> <cpp:directive>
#undef <cpp:undef> <cpp:directive> <name>
#warning <cpp:warning> <cpp:directive>
cpp:directive <cpp:directive>
cpp:file <cpp:file>
cpp:literal <cpp:literal>
cpp:macro <cpp:macro>
cpp:number <cpp:number>
cpp:value <cpp:value>

#


Element

  • <cpp:empty>

XPath Query

  • blank preprocessor lines

    //cpp:empty

Example

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

#define


Element

  • <cpp:define>

Subelements

  • <cpp:directive>
  • <cpp:macro>
  • <cpp:value>

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>

#endif


Element

  • <cpp:endif>

Subelement

  • <cpp:directive>

XPath Query

  • uses of #endif

    //cpp:endif

Example

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

#error


Element

  • <cpp:error>

Subelement

  • <cpp:directive>

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>

#if


Element

  • <cpp:if>

Subelements

  • <cpp:directive>
  • <expr>

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>

#ifndef


Element

  • <cpp:ifndef>

Subelements

  • <cpp:directive>
  • <expr>

XPath Query

  • uses of #ifndef

    //cpp:ifndef

Example

#ifndef test
#define final
#endif
<cpp:ifndef>#<cpp:directive>ifndef</cpp:directive> <name>test</name></cpp:ifndef>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>final</name></cpp:macro></cpp:define>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>

#include


Element

  • <cpp:include>

Subelements

  • <cpp:directive>
  • <cpp:file>

XPath Queries

  • includes

    //cpp:include
  • 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>

#line


Element

  • <cpp:line>

Subelements

  • <cpp:directive>
  • <cpp:number>
  • <cpp:file>

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>

#pragma


Element

  • <cpp:pragma>

Subelement

  • <cpp:directive>

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>

#undef


Element

  • <cpp:undef>

Subelements

  • <cpp:directive>
  • <name>

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>

#warning


Element

  • <cpp:warning>

Subelement

  • <cpp:directive>

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>

cpp:directive


Element

  • <cpp:directive>

XPath Query

  • cpp directives

    //cpp:directive

cpp:file


Element

  • <cpp:file>

XPath Query

  • cpp files

    //cpp:file

cpp:literal


Element

  • <cpp:literal>

XPath Query

  • cpp literals

    //cpp:literal

cpp:macro


Element

  • <cpp:macro>

XPath Query

  • cpp macros

    //cpp:macro

cpp:number


Element

  • <cpp:number>

XPath Query

  • cpp numbers

    //cpp:number

cpp:value


Element

  • <cpp:value>

XPath Query

  • cpp values

    //cpp:value