Table of Contents

CPP

This is the documentation of the CPP module that implements the cpp language. This is a wrapper of the C pre-processor facility. It may be used to define and use CPP macros inside JavaScript code. This module should not be directly loaded but used to specify a language when requiring another module. For instance:

Use require( "./example.js", "cpp" )

Configuration

The CPP compiler reads the file RCDIR/cpprc.json if it exists into a variable named config in the rest of this documentation. This file may override default CPP configuration. The default configuration is:

{
   "commandLine": "%s %s -undef -D__HOP__=1 -E -x c %s -o %s",
   "disableLinenumOpt": "-P"
}

The commandLine property value is used to build the actual C compiler invokation. It is build with the expression:

util.format( rc.commandLine,
             config && config.cc || require( hop.config ).bigloo[ "c-compiler" ],
             #:bigloo-debug() > 0 ? "" : config.disableLinenumOpt,
             file, target );

Example

The following example shows a source code that uses macro. It must be loaded with:

require( "./example.js", "cpp" );

The example is defined as:

example.js

"use strict";

#include "./op.js"

function identity( x ) {
#if( defined( __HOP__ ) )    
   return INC( DEC( x ) );
#else
   return x;
#endif
}

exports.identity = identity;

The included file is defined as:

op.js

#define INC( x ) (x + 1)
#define DEC( x ) (x - 1)