[previous] MISRA-C:2004  Rule  20.2:  (Required) [next] The names of standard library macros, objects and functions shall not be reused.
Where new versions of standard library macros, objects or functions are used by the programmer (e.g. enhanced functionality or checks of input values) the modified macro, object or function shall have a new name. This is to avoid any confusion as to whether a standard macro, object or function is being used or whether a modified version of that function is being used. So, for example, if a new version of the sqrt function is written to check that the input is not negative, the new function shall not be named "sqrt", but shall be given a new name.

Example Code:


/* PRQA S 2983,2984,3203 ++ */

#include "misra.h"
#include "m2cmex.h"

static F32 sqrt( F32 d );             /* MISRA Violation */
static S16 _test_2002a( void );       /* MISRA Violation */

enum { EOF = -1 };                    /* MISRA Violation */
enum { cos = 55 };                    /* MISRA Violation */
enum tm { t1, t2, t3 };               /* MISRA Violation */

typedef int FILE;                     /* MISRA Violation */
typedef signed int sin;               /* MISRA Violation */

extern S16 test_2002( void )
{
   F32  f;
   FILE r;
   sin  s = 5;

   f = sqrt( 1.44F );
   r = _test_2002a();
   r = r + s;


   return r;
}

static F32 sqrt( F32 d )              /* MISRA Violation */
{
   return( d );
}

static S16 _test_2002a( void )        /* MISRA Violation */
{
   return 1;
}


QAC messages that encompass this guideline:

0602 [U] The identifier '%s' is reserved for use by the library.
4602 The identifier '%1s' is declared as a macro in '<%2s>'.
4603 The object/function '%1s'is being defined with the same name as an ordinary identifier defined in '<%2s>'.
4604 The object/function '%1s' is being declared with the same name as an ordinary identifier defined in '<%2s>'.
4605 The typedef '%1s' is also defined in '<%2s>'.
4606 The typedef '%1s' has the same name as another ordinary identifier in '<%2s>'.
4607 The enum constant '%1s' has the same name as another ordinary identifier in '<%2s>'.
4608 The tag '%1s' is also defined in '<%2s>'.


Related rules:

Rule  1.2 No reliance shall be placed on undefined or unspecified behaviour.



(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