此为 Mathematica 8 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.2)

ToCCodeString

ToCCodeString[symbolicC]
generates a string of C code from a symbolic C expression.
  • SymbolicC expressions are inert; they evaluate to themselves, staying in an unevaluated form.
  • SymbolicC expressions can be converted into a C string with .
To use SymbolicC you first need to load the package:
This creates an entire program:
To use SymbolicC you first need to load the package:
In[1]:=
Click for copyable input
This creates an entire program:
In[2]:=
Click for copyable input
Out[2]=
Writing programs that write other programs, also called "metaprogramming" or simply "code generation", is a useful technique in generating specialized and optimized code:
SymbolicC can create domain-specific languages in Mathematica and translate them to C. This example defines a simple language that converts Mathematica points and polygons into calls to the OpenGL API:
Since understands the C operator precedence rules, it can decrease the number of parentheses in the program: