CForm

CForm[expr]

prints as a C language version of expr.

Details

  • Standard arithmetic functions and certain control structures are translated.
  • No declarations are generated.
  • CForm acts as a wrapper, which affects printing, but not evaluation.

Examples

open allclose all

Basic Examples  (1)

A C language version of a polynomial:

A mixed numeric and symbolic expression:

Scope  (1)

C formatting for an arbitrary function:

A composite power:

A vector:

A matrix:

Applications  (1)

Compute the analytic Hessian for a multivariate function for use in C code:

Properties & Relations  (2)

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:

Possible Issues  (1)

Names of functions output by CForm may be different from the names used by the specific C library:

In order to compile the C code generated, a header file found at the following location may need to be included:

Introduced in 1988
 (1.0)