04-06-2009, 10:14 AM
I think the example in the original post violates 5.5, the rule is pretty clear.
Although I also think the rule is strange: it should be sufficient to not give identifiers at file scope the same name as any other identifier at file scope.
Why it is enforced for static variables, I have no idea. It is contradicting, how can the programmer be confused about scope if he wrote static in the
first place? The rule must assume that an incompetent programmer will read code written by a competent one and then get confused because he lacks
knowledge in the C language.
Personally I think we could safely assume that a programmer writing safety-critical applications at least understand the concepts of scope and namespace,
as these are very fundamental and even beginner programmers know of them.
Rule 5.6 is even stranger, to conform with that rule you can't even use "i" for iterators, you must give them unique names... Also, by that rule you
can't name your variables the same as identifiers existing in the compiler libraries, so in order to conform with these two rules, you must read through
all code in the compiler libraries. Without a static analyzer it would be completely impossible to conform with them.
Luckily, both 5.5 and 5.6 are advisory. Is there anyone actually enforcing them in their MISRA implementation?
Although I also think the rule is strange: it should be sufficient to not give identifiers at file scope the same name as any other identifier at file scope.
Why it is enforced for static variables, I have no idea. It is contradicting, how can the programmer be confused about scope if he wrote static in the
first place? The rule must assume that an incompetent programmer will read code written by a competent one and then get confused because he lacks
knowledge in the C language.
Personally I think we could safely assume that a programmer writing safety-critical applications at least understand the concepts of scope and namespace,
as these are very fundamental and even beginner programmers know of them.
Rule 5.6 is even stranger, to conform with that rule you can't even use "i" for iterators, you must give them unique names... Also, by that rule you
can't name your variables the same as identifiers existing in the compiler libraries, so in order to conform with these two rules, you must read through
all code in the compiler libraries. Without a static analyzer it would be completely impossible to conform with them.
Luckily, both 5.5 and 5.6 are advisory. Is there anyone actually enforcing them in their MISRA implementation?
<t></t>