AUTOSAR A16-0-1: possible contradiction?

9 Ansichten (letzte 30 Tage)
dino spiller
dino spiller am 15 Aug. 2022
Beantwortet: Walter Roberson am 15 Aug. 2022
Good morning to all community,
I'd like to ask your support for managing a situation that looks hard (for me) to deal with.
I'm trying to fix some violations detected by Polyspace about rule A16-0-1.
The more complex to fix are "aliases" like:
#define MAYBE_UNUSED __attribute__((unused))
This is a very-used macro and for sure I cannot replace it just with something like:
using MAYBE_UNUSED=__attribute__((unused));
Also I tried to replace it creating an equivalent symbol with CMAKE, but it does not allow me to do so.
Do you have any suggestion based on your experience?
Another "weird" point is this contradiction (in my opinion):
The rule A16-0-1 states: "The pre-processor shall only be used for unconditional and conditional file
inclusion and include guards, and using the following directives: (1) #ifndef,
#ifdef, (3) #if, (4) #if defined, (5) #elif, (6) #else, (7) #define, (8) #endif, (9)
#include."
Which implies that you cannot use preprocessor for aliases, macros &co...
The problem is that M16-0-6 explicitly talks about function-like macros.
M16-0-6 states: "In the definition of a function-like macro, each instance of a parameter shall
be enclosed in parentheses, unless it is used as the operand of # or ##."
Honestly I see a contradiction. We discussed it in our team, without getting big ideas.
What can you tell about this?
  2 Kommentare
Walter Roberson
Walter Roberson am 15 Aug. 2022
Which implies that you cannot use preprocessor for aliases, macros &co...
I do not read it that way, as you are using #define which is one of the listed permitted preprocessor directives.
I would read it as not permitting preprocessort directives that are not in the list. For example not using #asm
dino spiller
dino spiller am 15 Aug. 2022
Sorry but I want to underline again that A16-0-1 states: "The pre-processor shall only be used for unconditional and conditional file inclusion and include guards". This is why I interpreted that "you cannot use preprocessor for aliases, macros...". Polyspace is complaining me if I try to write macros...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 15 Aug. 2022
I looked at the Rationale in the AutoSar CPP14 Guidelines... and you are right, you can't do that.
Since C++17 you can use the attribute maybe_unused -- and you can use that with a "using" statement. https://en.cppreference.com/w/cpp/language/attributes/maybe_unused

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by