Synopsis: | For a struct the initializer should be {0} or all fields should be initialized. |
Language: | C |
Severity Level: | 4 |
Category: | Declarations |
Description: |
Justification Readability. Example 1 typedef struct xyz { float x; float y; float z; } xyz_vect; xyz_vect a = {0}; /* RIGHT */ xyz_vect b = {1.0, 3.5, 6.7}; /* RIGHT */ xyz_vect c = {1.0, 3.5} /* WRONG: c is interpreted as {1.0, 3.5, 0.0} */ Example 2 typedef struct rotate { xyz_vect hor; float Rx; float Ry; float Rz; } rotate_vect; typedef struct foo { xyz_vect hor; rotate_vect rot; } foo_vect; foo_vect a = {{0}, {0}}; /* RIGHT */ foo_vect b = {{1.0, 3.5, 6.7}, {0}}; /* RIGHT */ foo_vect c = { {1.0, 3.5}, /* WRONG: c.hor is interpreted as {1.0, 3.5, 0.0}. */ {3.1415, 1.41, 0.707} /* Unknown if this was intended by the programmer */ |