[previous] MISRA-C:2004  Rule  5.6:  (Advisory) [next] No identifier in one name space should have the same spelling as an identifier in another name space, with the exception of structure member and union member names.
Name space and scope are different. This rule is not concerned with scope. For example, ISO C allows the same identifier (vector) for both a tag and a typedef at the same scope.

typedef struct vector { 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:

struct device_q { struct device_q *next;  /* ... */ } devices[N_DEVICES];
struct task_q { struct task_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