You can generate MISRA C++ compliant code if you add the
MISRA C++ settings and the MISRA C++ types to your Rational® Rhapsody® model.
About this task
Note: For a framework that is highly compliant with MISRA/C++,
it is recommend to use the Simplified C++ Execution Framework (SXF)
.
Procedure
- To add MISRA C++ settings and MISRA C++ types to your model,
open your model in Rational Rhapsody for C++.
- Select , go to <product
installation path>\Share\Settings\MISRA, select
the MISRAC++.sbs file, and click OK. These
settings add a number of properties to your model that make the Rational Rhapsody code generator MISRA C++ compliant.
- To add the MISRA_Cpp_Types package to your model, select , go to <product installation
path>\Share\LangCpp\oxf\model\oxf_rpy, select
the MISRA_Cpp_Types.sbs file, and click OK.
This package contains the MISRA C++ types.
- Use the MISRA C++ types instead of the C++ basic types,
such as int and char.
What to do next
Rational Rhapsody supports the following
MISRA C++ rules:
- 7-1-1: A variable which is not modified must be constant
qualified
- 0-1-7: The value returned by a function that has
a non-void return type that is not an overloaded operator must always
be used
- 5-14-1: The right hand operand of a logical && or || operator
must not contain side effects
- 6-4-2: All if...elsemust be terminated
with an else clause
- 5-0-2: Limited dependence needs to be placed on C++
operator precedence rules in expressions
Note: - To avoid a violation of MISRA C++ rules 5-2-4, 7-1-2, and 18-4-1,
do not use ports.
- Per MISRA C++ rule 18-4-1, dynamic heap memory allocation cannot
be used. You can avoid dynamic memory allocation by statically creating
events and then using send(&theEvent) to send
them.
The following properties have values of:
- CPP_CG::Argument::IsConst = True
- CPP_CG::Attribute::GenMutatorConstantArgument= True
- CG::Attribute/ Relation ::IsConst = SignatureAndReturnValue
You need to consider that:
- For using new or delete in ports, all
attributes generated for ports are by value so no new or delete is
generated.
- Framework changes:
OMEvent::isTypeOf had changed from
bool OMEvent::isTypeOf(IOxfEvent::ID eventId) const
bool OMEvent::isTypeOf(const IOxfEvent::ID eventId) const
Because
framework’s base classes are defined before user inheritance, so are
their initializations. For example, AcmeJet::AcmeJet(void)
: OMThread(), Jet() {. The base class initialization is turned
off by default to regular models.
- The default visibility of relations in MisraC++ is private.
- In Statecharts without inheritance, attributes are
now private and defined as enum.
- In Statecharts with inheritance, attributes are protected
and as integers, which is not MISRA compliant. A CG warning
is issued, and an LDRA warning is added to the code.
- For MISRA C++ models event arguments:
- Adding a new Boolean property CPP_CG:Event:GenerateArgumentsAsPrivate,
if checked, the visibility of the arguments have a value of private.
- For all models the annotation of Event’s argument is now //##
auto_generated