/* >>>------------------------------------------------------------ * * File: rule_5.6.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 5.6 (Advisory): * 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. * * Implemented by messages: * 780 Another identifier '%s' is already in scope in a * different namespace. * * 781 '%s' is being used as a structure/union member as well * as being a label, tag or ordinary identifier. * * <<<------------------------------------------------------------ */ /* PRQA S 2015,2983,2984,3202,3205,3408 ++ */ #include "misra.h" #include "m2cmex.h" static void test_0506a( void ); static void test_0506b( void ); static void test_0506c( void ); static void test_0506d( void ); extern S16 test_0506( void ) { test_0506a(); test_0506b(); test_0506c(); test_0506d(); return 0; } /******************************************************* Four name spaces are defined in the C language 1) label names 2) tags of structure, unions and enums 3) members of structures and unions 4) ordinary identifiers (variables, functions, typedefs) This means that, WITHIN THE SAME SCOPE, ISO C permits the declaration of an object with the same name as a structure tag but does not permit the declaration of an object with the same name as a typedef. *******************************************************/ /* LABEL NAMES lab1 conflicts with structure tag lab1 lab2 conflicts with structure member st.lab2 lab3 conflicts with object identifier lab3 */ static void test_0506a( void ) { S32 r = 0; struct lab1 { S32 x; }; struct st { S32 lab2; }; S32 lab3; lab1: /* MISRA Violation */ ++r; lab2: /* MISRA Violation */ ++r; lab3: /* MISRA Violation */ ++r; } /* TAGS OF STRUCTURES, UNIONS AND ENUMS st1 conflicts with label st1 st2 conflicts with structure member st.st2 st3 conflicts with object identifier st3 */ static void test_0506b( void ) { S32 r = 0; struct st1 { S32 n1; }; struct st2 { S32 n2; }; struct st { S32 st2; }; /* MISRA Violation */ struct st3 { S32 st1; }; /* MISRA Violation */ S32 st3; /* MISRA Violation */ st1: /* MISRA Violation */ ++r; } /* MEMBERS OF STRUCTURES AND UNIONS m1 in structure st1 conflicts with label m1 m2 in structure st2 conflicts with structure tag m2 m3 is a member name in structures st3 and st - not a MISRA violation m4 in structure st4 conflicts with object identifier m4 */ static void test_0506c( void ) { S32 r = 0; struct st1 { S32 m1; }; struct st2 { S32 m2; }; struct m2 { S32 m; }; /* MISRA Violation */ struct st3 { S32 m3; }; struct st { S32 m3; }; /* OK */ struct st4 { S32 m4; }; S32 m4; /* MISRA Violation */ m1: /* MISRA Violation */ ++r; } /* IDENTIFIERS id1 conflicts with label id1 id2 conflicts with structure tag id2 id3 conflicts with structure member st3.id3 */ static void test_0506d( void ) { S32 r = 0; S32 id1; S32 id2; struct id2 { S32 n; }; /* MISRA Violation */ S32 id3; struct st3 { S32 id3; }; /* MISRA Violation */ id1: /* MISRA Violation */ ++r; }