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

Rule:  6.7.8.bChecked automatically with code checker

Synopsis:The initializer for a struct, union or array shall be enclosed in braces.
Language:C
Severity Level:4
Category:Declarations


Description:

Justification

Readability.

Example 1

typedef struct xy
{
   int x;
   int y;

} xyvect;

xyvect origin = 0; /* WRONG */
xyvect point = /* RIGHT */
{            
   0,
   0
};

origin = point; /* assignment */

Example 2

#define CCBB_STX 0x02
#define CCBB_EOT 0x04
#define CCBB_ACK 0x06

static const char ccbb_protocol[3] = /* RIGHT */
{
   CCBB_STX,
   CCBB_EOT,
   CCBB_ACK
};

Exception

Initialization of a character array with a string literal does not require braces:

static const char ccbb_msg[] = "My message";

Note

When copying structs with pointers as members, be aware that the pointer is duplicated and not the memory it is referring to.