This example shows how to export the definition and declaration of a global variable that the generated code uses as a signal.
float mySig;
extern float mySig;
1. Open the example model ex_defn_decl
.
2. In the Model Data Editor, open the Inports/Outports tab.
3. From the Change view drop-down list, select Design
.
4. In the Model Data Editor, for the Inport block, set Signal Name to mySig
.
5. Set Data Type to single
.
6. From the Change view drop-down list, select Code
.
7. For the Inport block, set Storage class to ExportToFile
.
8. Set Header File to myDecls.h
.
9. Set Definition File to myDefns.c
. Click OK.
10. Generate code from the model.
The generated header file myDecls.h
declares the global variable myParam
by using the extern
keyword.
/* Declaration for custom storage class: ExportToFile */ extern real32_T mySig; /* '<Root>/In1' */
The generated source file myDefns.c
defines and initializes myParam
.
/* Definition for custom storage class: ExportToFile */ real32_T mySig; /* '<Root>/In1' */