Several standard methods are available for setting up a model to generate specific C constructs in your generated code. Using blocks, S-functions, Stateflow charts, MATLAB Function blocks, data objects, and custom storage classes, you can generate C constructs such as: data types, structures, arrays, control flow constructs, functions, preprocessor directives, and pointers. To begin, see Prepare a Model for Code Generation.
Create data type aliases by generating typedef
statements.
Definition, Initialization, and Declaration of Parameter Data
Control the file placement of the declaration, definition, and initialization of parameter data.
Definition and Declaration of Signal Data
Control the file placement of the declaration and definition of signal data.
Create a data type conversion using a Data Type Conversion block, Stateflow Chart, or MATLAB Function block.
Apply the const
and volatile
keywords
to a global variable that represents parameter data.
Relational and Logical Operators
Implement relational and logical operators using Simulink blocks, Stateflow Charts, and MATLAB Function blocks.
Perform bitwise operations using the Bitwise Operator block, a Stateflow Chart, or MATLAB Function block.
To generate an enumerated data type, define an enumeration class in a MATLAB file.
Use a Switch block, a Stateflow Chart, or MATLAB
Function block to create an if-else
statement in
the generated code.
Use a Switch Case block or MATLAB Function block to create an
switch
statement in the generated code.
Use a For-Iterator Subsystem block, Stateflow Chart,
or MATLAB Function block to create a for
loop in
the generated code.
Use a White Iterator Subsystem block, Stateflow Chart,
or MATLAB Function block to create a while
loop
in the generated code.
Use a While Iterator Subsystem block or Stateflow
Chart to create a do while
loop in the generated
code.
To generate a function call, add a subsystem, which implements the operations that you want.
Create a function call using graphical functions or function prototype control.
Integrate legacy C functions in the generated code by either creating an S-function or making a call to an external C function.
Generate parameter data as a constant-valued macro.
Conditional Inclusions (#if / #endif)
Include preprocessor conditionals in your generated code by implementing variant blocks in your model.
Create a flat structure or nested structures that store parameter data in the generated code.
Create a flat structure that contains signal data in the generated code.
Create a structure whose fields are also structures.
Store Boolean data in bitfields in the generated code.
Create an array of parameter data in the generated code.
Create an array of signal data in the generated code.