| Contents | Index |
To open a model for generating preprocessor conditionals, enter rtwdemo_preprocessor.
After building the model, look at the variants in the generated code. rtwdemo_preprocessor_types.h includes the following:
Call to external header file, rtwdemo_preprocessor_macros.h, which contains the macro definition for the variant control variable, MODE.
/* Includes for objects with custom storage classes. */ #include "rtwdemo_importedmacros.h"
Preprocessor directives defining the variant objects, LINEAR and NONLINEAR. The values of these macros depend on the value of the variant control variable, MODE. The condition expression associated with each macro, LINEAR and NONLINEAR, determine the active variant.
/* Model Code Variants */ #ifndef LINEAR #define LINEAR (MODE == 0) #endif #ifndef NONLINEAR #define NONLINEAR (MODE == 1) #endif
Check that exactly one variant is active at a time:
/* Exactly one variant for '<Root>/Left Controller' should be active */ #if (LINEAR) + (NONLINEAR) != 1 #error Exactly one variant for '<Root>/Left Controller' should be active #endif
Calls to the step and initialization functions are conditionally compiled as shown in a portion of the step function, rtwdemo_preprocessor_step, in ModRefVar.c:
#if LINEAR
/* ModelReference: '<Root>/Left Controller' */
rtwdemo_linl(&rtb_Add, &rtb_LeftController_merge_1,
&(rtwdemo_preprocessor_DWork.LeftController_1_DWORK1.rtdw));
#elif NONLINEAR
/* ModelReference: '<Root>/Left Controller' */
rtwdemo_nlinl(&rtb_Add, &rtb_LeftController_merge_1,
&(rtwdemo_preprocessor_DWork.LeftController_2_DWORK1.rtdw));
#endif /* LINEAR */
and
#if LINEAR
/* ModelReference: '<Root>/Right Controller' */
rtwdemo_linr(&rtb_Add1, &rtb_RightController_merge_1,
&(rtwdemo_preprocessor_DWork.RightController_1_DWORK1.rtdw));
#elif NONLINEAR
/* ModelReference: '<Root>/Right Controller' */
rtwdemo_nlinr(&rtb_Add1, &rtb_RightController_merge_1,
&(rtwdemo_preprocessor_DWork.RightController_2_DWORK1.rtdw));
#endif /* LINEAR */
![]() | Review Code Variants in the Code Generation Report | Generate Code for Variant Subsystems | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |