Main Content

Definition, Initialization, and Declaration of Parameter Data

This example shows how to export the definition, initialization, and declaration of a global variable that the generated code uses as a parameter.

C Construct

int32 myParam = 3;

extern int32 myParam;


1. Open the example model ex_defn_decl.

2. In the model, select the Gain block. In the Property Inspector, set the value of the Gain parameter to myParam.

3. Next to the parameter value, click the action button (the button with three vertical dots) and select Create.

4. In the Create New Data dialog box, set Value to Simulink.Parameter(3). Click Create. A Simulink.Parameter object, myParam, appears in the base workspace. The Gain block uses the object to set the value of the Gain parameter, in this case, 3.

5. In the Simulink.Parameter property dialog box, set Data type to int32.

6. Set Storage class to ExportToFile.

7. Set Header File to myDecls.h.

8. Set Definition File to myDefns.c. Click OK.

9. To build the model and generate code, press Ctrl+B.


The generated header file myDecls.h declares the global variable myParam by using the extern keyword.

/* Declaration for custom storage class: ExportToFile */
extern int32_T myParam;                /* Referenced by: '<Root>/Gain' */

The generated source file myDefns.c defines and initializes myParam.

/* Definition for custom storage class: ExportToFile */
int32_T myParam = 3;                   /* Referenced by: '<Root>/Gain' */

Related Topics