The C Preprocessor

SymbolicC has a number of functions for working with the C preprocessor. These allow you to set up including header files, defining macros, as well as setting up conditional compilation.

Working with Header Files

First, you need to load the package.

In[1]:=
Click for copyable input

Now you can include a header file with CInclude.

In[2]:=
Click for copyable input
Out[2]=

If it is a system header file, this is dealt with appropriately.

In[3]:=
Click for copyable input
Out[3]=

You can add a list of header files in one CInclude expression.

In[4]:=
Click for copyable input
Out[4]=

It is also possible to use CComment to add a comment to an include statement.

In[5]:=
Click for copyable input
Out[5]=

Defining Macros

You can define a macro using CDefine.

First, you need to load the package.

In[1]:=
Click for copyable input

Now you can define a macro.

In[2]:=
Click for copyable input
Out[2]=

You can combine the definition with other SymbolicC functions.

In[3]:=
Click for copyable input
Out[3]=

You can also add a comment by adding a CComment expression.

In[4]:=
Click for copyable input
Out[4]=

Conditional Compilation

There are a range of functions to create C preprocessor conditional compilation output.

First, you need to load the package.

In[1]:=
Click for copyable input

Now you can create a conditional compilation output.

In[2]:=
Click for copyable input
Out[2]=

You can also add an entire command.

In[3]:=
Click for copyable input
Out[3]=

CPreprocessorIfdef can create an entire sequence.

In[4]:=
Click for copyable input
Out[4]=

The conditional compilation output commands are summarized in the following table.

CPreprocessorIf#if a == 1
CPreprocessorIfdef#ifdef DEBUG
CPreprocessorIfndef#ifndef DEBUG
CPreprocessorElse#else
CPreprocessorElif#elif b
CPreprocessorEndif#endif

C preprocessor conditional compilation output.