This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

CForm

CForm[expr]
prints as a C language version of expr.
  • Standard arithmetic functions and certain control structures are translated.
  • No declarations are generated.
  • CForm acts as a "wrapper", which affects printing, but not evaluation.
A C language version of a polynomial:
A mixed numeric and symbolic expression:
A C language version of a polynomial:
In[1]:=
Click for copyable input
Out[1]//CForm=
A mixed numeric and symbolic expression:
In[2]:=
Click for copyable input
Out[2]//CForm=
C formatting for an arbitrary function:
A composite power:
A vector:
A matrix:
Compute the analytic Hessian for a multivariate function for use in C code:
CForm formats expressions like C code:
FortranForm formats expressions like Fortran code:
Splice can be used to convert expressions in a file:
The following C file contains the unevaluated integral:
Splice inserts the result of the integral:
The spliced file:
Additional C function definitions may be needed to run the code:
Here is a template for such an include file (shown on a typical Windows installation):
New in 1