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.
  • When an input evaluates to CForm[expr], CForm does not appear in the output. »

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)

When an input evaluates to CForm[expr], CForm does not appear in the output:

Out is assigned the value x2, not CForm[x^2]:

CForm formats expressions like C code:

FortranForm formats expressions like Fortran code:

Possible Issues  (2)

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:

Even when an output omits CForm from the top level, it is not stripped from subexpressions:

The output does not have CForm in it:

However, the variable e does have CForm in it, which may affect subsequent evaluations:

The product is not evaluated due to the intervening CForm:

Assign variables first and then apply CForm to the result to maintain computability:

Wolfram Research (1988), CForm, Wolfram Language function, https://reference.wolfram.com/language/ref/CForm.html.

Text

Wolfram Research (1988), CForm, Wolfram Language function, https://reference.wolfram.com/language/ref/CForm.html.

BibTeX

@misc{reference.wolfram_2020_cform, author="Wolfram Research", title="{CForm}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/CForm.html}", note=[Accessed: 15-April-2021 ]}

BibLaTeX

@online{reference.wolfram_2020_cform, organization={Wolfram Research}, title={CForm}, year={1988}, url={https://reference.wolfram.com/language/ref/CForm.html}, note=[Accessed: 15-April-2021 ]}

CMS

Wolfram Language. 1988. "CForm." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CForm.html.

APA

Wolfram Language. (1988). CForm. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CForm.html