SymbolicC provides automated formatting of the generated C output. This section reviews some of the ways that you can work with formatting to create your own styles of output.

Atomic Input

Atomic input such as variables or numbers can be passed in as typical Wolfram Language input or as a string.

First, you need to load the package.

You can enter a variable as a Wolfram Language symbol. Note how ToCCodeString creates the C-formatted output.

You can also enter the variable as a Wolfram Language string.

Integers can be entered directly.

Floating-point numbers can also be entered directly.

The numbers might be output using an exponential notation.

Of course, you could use a string to create the result as well.

If you want to specify the type of a numeric value, you can use CConstant.


You can output strings into the C code using the CString wrapper.

First, you need to load the package.

This creates a C string.


There are a number of ways that you can modify the formatting of comments.

First, you need to load the package.

This outputs a comment. Note how the contents of the comment are padded with spaces.

You can add a space before the comment, and have a return after.

Statements and Expressions

SymbolicC attempts to distinguish between statements, which do not return anything, and expressions, which do return a result.

First, you need to load the package.

When converting a statement such as a declaration to a string, it is terminated with a semicolon and a new line as shown below.

Alternatively, when an expression is formatted, no semicolon or new line is added.

If you want to add a semicolon and new line then you can place the argument inside a list.

If you want to enclose the statements into a block, you should use CBlock.

Note that constructs, such as CBlock, automatically turn their arguments into statements.


CExpression lets you include C code generated using the Wolfram Language formatting function CForm.

First, you need to load the package.

Here the result is generated by CForm.

If the input would evaluate, as in this Set expression, you need to use HoldForm.

You can include a semicolon by inserting the arguments into a list.