Generated Code Structure for
PLC_PreventExternalVarInitialization
The example shows you how to enable the
PLC_PreventExternalVarInitialization option for your model, generate code
and display the comparison between code generated with the
PLC_PreventExternalVarInitialization option disabled and then
enabled.
Open the
PLC_PreventExternalVarInitializationExampleexample:.openExample('plccoder/PreventExternalVarInitializationExample')Copy all the model files to a folder of your choice.
Open the
External_Var_Distributed_Codegenmodel.Open the Simulink PLC Coder app, and select the
Subsystemblock.Click Settings. Navigate to PLC Code Generation > Interface. Clear the Remove initialization statements for externally defined state variables check box.
Click OK.
Click Generate PLC Code.
Select the
Subsystemblock.Click Settings. Navigate to PLC Code Generation > Interface. Set the Remove initialization statements for externally defined state variables check box.
Click Generate PLC Code.
This image shows a comparison between the code generated with
PLC_PreventExternalVarInitialization disabled, and then enabled. Removing
initialization statements for externally defined variables prevents the corruption of their
data values.

See Also
Remove Initialization Statements for Externally Defined State Variables