TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
ASML C Coding Standard
Search

Rule:  6.5.3.2.aChecked automatically with code checker

Synopsis:A variable declared as an array shall not be used as a pointer.
Language:C
Severity Level:6
Category:Expressions


Description:

Justification

An array name acts as a pointer to the first element of the array. However, using it that way can be a source of programming errors if the programmer forgets to process other elements of the array.

Example 1

{
   int a[10];

   *a = 1; /* WRONG */
   a[0] = 1; /* RIGHT */
}

Example 2

typedef struct
{
   int x;
   int y;
} ccbb_struct_t;

static void ccbb_f(void)
{
   ccbb_struct_t a[3];

   a->x = 1; /* WRONG */
   a[0].x = 1; /* RIGHT */
}

Note

An array name can be assigned to a pointer, making it a pointer to an array element. In this case, the programmer's intention is clear.

Example 3

{
   int a[10];
   int *a_p;

   *a = 1; /* WRONG */

   a_p = a;
   *a_p = 1; /* RIGHT */
}