![]() |
|
MISRA-C:2004 Rule 5.6: (Advisory) |
|
||||
![]() | |||||||
typedefstructvector{uint16_t x ; uint16_t y; uint16_t z;}vector;/* Rule violation ^^ ^^ */
ISO C defines a number of different name spaces (see ISO/IEC 9899:1990 6.1.2.3 [2]). It is technically possible to use the same name in separate name spaces to represent completely different items. However this practice is deprecated because of the confusion it can cause, and so names should not be reused, even in separate name spaces.
The example below illustrates a violation of this rule in which value is inadvertently used instead of record.value:
struct{int16_t key; int16_t value;}record; int16_t value;/* Rule violation - 2nd use of value */record.key=1; value=0;/* should have been record.value */
By contrast, the example below does not violate the rule because two member names are less likely to be confused:
structdevice_q{structdevice_q*next;/* ... */}devices[N_DEVICES];structtask_q{structtask_q*next;/* ... */}tasks[N_TASKS]; devices[0].next=&devices[1]; tasks[0].next=&tasks[1];
QAC messages that encompass this guideline:
| 0780 | Another identifier '%s' is already in scope in a different namespace. |
| 0781 | '%s' is being used as a structure/union member as well as being a label, tag or ordinary identifier. |
|
||
(c) The Motor Industry Research Association, 2004
|
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2 © 2013 Programming Research www.programmingresearch.com |
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |