2

I am reading company's coding guidelines, and I encountered the MISRA 8-0-1 rule, which states:

An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or member-declarator respectively.

No example.

So, what is this rule about? Can anyone provide some example of this (bad and good)?

  • I assume you are referring to the MISRA-C++ 2008 manual, if so there are examples (page 115), such as: int32_t *i3, &j3 = i2; and other ugliness. – Veriloud Apr 20 '16 at 10:00
1

The syntax of init-declarator-lists is:

init-declarator-list:
       init-declarator
       init-declarator-list , init-declarator
init-declarator:
       declarator initializer

So it seems they are saying a init-declarator-list should contain only 1 init-declarator at a time.

so instead of

int a,b;

they want

int a;
int b;

(although they could be talking about initialisation fo the variable too, ie int a = 0; and not int a = 0, b = 0; even they do not talk about initalizers only init-declarators)

my opinion: "meh". This is why coding standards are poop.

|improve this answer|||||
  • 5
    I assume part of the motivation is to avoid weirdness like int* a, b; – Ixrec Apr 20 '16 at 8:17
  • 1
    Anything that could be slightly ambiguous for a casual reader is removed in MISRA-C. For example int* a, b;. This is for critical systems, and in those areas they still use old but trusted tools. Restricting the language a lot simplifies the work of analyzers (I guess) – coredump Apr 20 '16 at 8:17
  • doh so simple. Couldn't they just put such example in the document?!? – BЈовић Apr 20 '16 at 8:21
  • @Ixrec sure, but I'd expect a coder to know better, or a code reviewer to slap anyone who didn't. But fair enough if Misra is for critical systems. – gbjbaanb Apr 20 '16 at 8:32
  • Right, say you're in a code review, you see something like this: int & k1 = *i1, l1; you'll want an explanation right? That's all MISRA is about, tells the developer to fix it or provide an explanation before wasting time in code review. – Veriloud Apr 20 '16 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.