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.
Needs["SymbolicC`"]Now you can include a header file with CInclude.
CInclude["exports.h"]//ToCCodeStringIf it is a system header file, this is dealt with appropriately.
CInclude["<foo.h>"]//ToCCodeStringYou can add a list of header files in one CInclude expression.
CInclude[{"<math.h>", "<stdlib.h>"}]//ToCCodeStringIt is also possible to use CComment to add a comment to an include statement.
{CInclude["exports.h"], CComment["Import the exports"]}//ToCCodeStringDefining Macros
You can define a macro using CDefine.
First, you need to load the package.
Needs["SymbolicC`"]CDefine["DEBUG"]//ToCCodeStringYou can combine the definition with other SymbolicC functions.
CDefine[CCall[ addMacro, {a, b}], COperator[Plus, {a, b}]]//ToCCodeStringYou can also add a comment by adding a CComment expression.
CDefine["DEBUG", CComment[ "Turn on debugging"]]//ToCCodeStringConditional Compilation
There are a range of functions to create C preprocessor conditional compilation output.
First, you need to load the package.
Needs["SymbolicC`"]Now you can create a conditional compilation output.
CPreprocessorIfdef["DEBUG"]//ToCCodeStringYou can also add an entire command.
CPreprocessorIfdef[COperator[Equal, {"a", 1}]]//ToCCodeStringCPreprocessorIfdef can create an entire sequence.
CPreprocessorIfdef["DEBUG64", CAssign[size, 64], CAssign[size, 32]]//ToCCodeStringThe conditional compilation output commands are summarized in the following table.