Consider the case where your model has variables defined
directly in a package. These variables define various constants (such
as PI and DEGREES_PER_RADIAN). Some
of these variables are defined in terms of others, such that the dependent
variable must be declared before the others for the application to
compile. However, the product does not allow you to override the default
alphabetic order of the variable declarations.
There are at least two ways to solve this
problem:
- Define your constants using types. For example,
assume a type named PI with the following declaration:
const double %s = 3.14
In this syntax, the %s is
replaced with the name PI.
A DEGREES_PER_RADIAN type
would have the following declaration:
const double %s = 180.0 / PI
In this syntax, the %s is
replaced with the name DEGREES_PER_RADIAN.
Because you can change the order of the type declarations
in Rational® Rhapsody®,
such that PI is generated first, the compilation is successful.
- Create a variable called PI of
type const double with an initial value of 3.14.
Create a second variable called DEGREES_PER_RADIAN of
type const double with an initial value of 180.0
/ PI. This will not compile because Rational Rhapsody generates
the DEGREES_PER_RADIAN variable before the PI variable.
On the DEGREES_PER_RADIAN variable, set the CPP_CG::Attribute::VariableInitializationFile property
to Implementation to initialize the variable in the
implementation file. The default setting (Default)
causes the initialization to be put in the specification file if the
type declaration begins with const; otherwise, it
is placed in the implementation file.
Now,
your application will compile correctly.