C Symbols
Which C functions, variables and types you get from your model, how they are named, and what happens when two names clash.
The names you give callbacks, signals and blocks on the canvas are the names you find in the generated C. To change a name, rename it in the model and generate again. Don’t rename it in the code.
What you get from a model
Each model generates <Model>.h and <Model>.c. Select an element to see the C symbol it becomes:
Each callback becomes one function with exactly the callback's name.
| In the model | In C | Example |
|---|---|---|
| Model | void <Model>_Init(void) |
Cruise_Init() |
| Callback | void <Callback>(void), named exactly as the callback |
Sense(), Control() |
| Model without callbacks | void <Model>(void) |
Cruise() |
| Callback sample interval | Macro <Callback>_DT_S, in seconds |
Control_DT_S |
| Model Input / Model Output | Variable | speed, throttle |
| Connection between two callbacks | Variable | speed_error |
| Logged signal with Exposure Public | Variable | motor_speed |
| Calibration parameter | volatile variable |
Kp |
| Memory block, such as Unit Delay or Integrator | Internal variable | integral |
| Parameter | Internal static const variable |
MaxTorque |
| Container | Internal function | PiController |
| State chart | Internal function and enum type for its states | ModeLogic, ModeLogic_State_t |
| Enumeration type | Enum type and constants | DriveMode_t, DriveMode_SPORT |
| Bus | Struct type | WheelData_bus_t |
<Model>_Init(), the callback functions, the _DT_S macros and the input, output, calibration and public variables are the model’s interface. Internal variables and functions appear in the code for review only.
A logged signal stays internal unless you set its Exposure to Public in the Data Manager. It then appears in <Model>.h under its signal name.
Enumeration types
A user-defined enumeration type becomes a C enum type. Each member becomes a constant with its value:
| In the model | In C | Example |
|---|---|---|
Type DriveMode |
<Type>_t |
DriveMode_t |
Member SPORT |
<Type>_<Member> |
DriveMode_SPORT |
Signal of type DriveMode |
Variable of type <Type>_t |
DriveMode_t active_mode; |
Literal DriveMode.ECO |
The member constant | DriveMode_ECO |
- Type and member names are kept exactly as written, including upper and lower case.
- The type name is always the prefix. Two types can share member names:
DriveMode_ECOandPowerMode_ECOare different constants. - Members appear in value order, each with its explicit value.
- Each type is declared once per build, even when several models use it.
Type and member names must be valid C identifiers. Modeloop checks this when you define the type.
The states of a state chart follow the same pattern. A chart named ModeLogic with states Idle and Active gives the type ModeLogic_State_t and the constants ModeLogic_State_Idle and ModeLogic_State_Active.
Buses
A bus becomes a C struct type with one field per bus element, each field named after its element. The type is named after the Bus Creator block that builds the bus, followed by _bus_t: a Bus Creator named WheelData gives WheelData_bus_t. A block name that already ends with _bus gets only _t.
How a name is chosen
Modeloop uses the first name you gave, in this order. If you gave none, it uses an automatic name.
| Element | 1st choice | 2nd choice | 3rd choice | Automatic name |
|---|---|---|---|---|
| Model Input / Output | Signal connected to it | Model Input / Output block name | tmp_in_1, tmp_out_1 |
|
| Connection between callbacks | Connection name | Signal on the producing output | Output name in the producing callback | irv_1 |
| Signal inside a callback | Signal name | Name of the block that produces it | tmp_sum_1 |
|
| Memory block | Its output signal name | Block name | tmp_st_1 |
|
| Container port | Signal name | Virtual Input / Output name | in_1, out_1 |
An automatic name for a connection between callbacks, a Container or a state chart is reported as an information message, so you can see which names are still worth giving.
Names become valid C identifiers: characters other than letters, digits and underscores become _, and a C keyword gets a trailing underscore, so for becomes for_. The name in your model stays unchanged.
Callback names are used exactly as written. A callback name must be a valid C identifier, must not be a C keyword, and must be unique across every model in the build. Otherwise, code generation stops and tells you which name to change.
When two names clash
Names stay exactly as you wrote them unless they clash. When two callbacks of the same model use the same name, only those symbols get the callback name as a prefix:
Here both callbacks read model input raw, so write both Fast_raw and Slow_raw. Adding a callback never renames a symbol that is still unique.
Code generation stops and asks you to rename one element when:
- Two different signals in the same callback or Container would get the same C name.
- Two models in the same build have a callback with the same name.
- Two names visible outside their file are identical in their first 31 characters, the length every C compiler is required to distinguish.
Naming tips
- Name signals at the model boundary.
wheel_speed_rpmis a better variable thantmp_in_1. - Name connections between callbacks. Otherwise they become
irv_1,irv_2and so on. - Name Containers and state charts after what they do. Their names appear as function names in the code.
- Use an enumeration type for modes.
DriveMode_SPORTis clearer in the code than2. - Keep callback names unique across the project. All callback functions share one namespace in your firmware.
- Keep exported names short. Model, callback and interface names that differ early are easier to read and stay distinct for every C compiler.