diff --git a/Documentation/NuttXCCodingStandard.html b/Documentation/NuttXCCodingStandard.html index 977af36225b..8689ef80587 100644 --- a/Documentation/NuttXCCodingStandard.html +++ b/Documentation/NuttXCCodingStandard.html @@ -12,7 +12,7 @@
Last Updated: February 9, 2017
+Last Updated: April 18, 2017
@@ -1291,14 +1291,28 @@ typedef int myinteger_t;struct in all structure definitions.
+ The exception to this rule is for structures that are defined within another union or structure (discouraged). In those cases, the structure name should always be omitted.
typdef-ing of structures;
normally the full structure name is used as types throughout the code.
+ The reason for this is that is structure pointers may be forward referenced in header files without having to include the file the provides the type definition.
+ This greatly reduces header file coupling.
Incorrect
-typedef struct
+typedef struct /* Un-named structure */
{
...
int val1, val2, val3; /* Values 1-3 */
@@ -1388,33 +1402,97 @@ struct xyz_information
bitc : 1; /* Bit C */
...
};
+
+struct abc_s
+{
+ ...
+ struct
+ {
+ int a; /* Value A */
+ int b; /* Value B */
+ int c; /* Value C */
+ }; /* Un-named structure field */
+ ...
+};
+
Correct
-
-struct xyz_info_s
-{
- ...
- int val1; /* Value 1. */
- int val2; /* Value 2. */
- int val3; /* Value 3. */
- ...
-};
-
--typdef struct xyz_info_s xzy_info_t; --
(The use of typedef'ed structures is acceptable but discouraged)
++ Correct +
struct xyz_info_s
{
...
- uint8_t bita : 1, /* Bit A. */
- uint8_t bitb : 1, /* Bit B. */
- uint8_t bitc : 1, /* Bit C. */
+ int val1; /* Value 1 */
+ int val2; /* Value 2 */
+ int val3; /* Value 3 */
...
};
+
+
++ Discouraged +
++typedef struct xyz_info_s xzy_info_t; ++
+ The use of typedef'ed structures is acceptable but discouraged. +
+ ++ Correct +
+
+struct xyz_info_s
+{
+ ...
+ uint8_t bita : 1, /* Bit A */
+ uint8_t bitb : 1, /* Bit B */
+ uint8_t bitc : 1, /* Bit C */
+ ...
+};
+
+
++ Discouraged +
+
+struct abc_s
+{
+ ...
+ struct
+ {
+ int a; /* Value A */
+ int b; /* Value B */
+ int c; /* Value C */
+ } abc;
+ ...
+};
+
++ The use of structures defined within other structures is acceptable provided that they define named fields. + The general practice of defining a structure within the scope of another structure, however, is still but discouraged in any case. + The following is preferred: +
+ ++ Correct +
+
+struct abc_s
+{
+ ...
+ int a; /* Value A */
+ int b; /* Value B */
+ int c; /* Value C */
+ ...
+};
+
Example
-union xyz_union_u
+union xyz_union_u /* All unions must be named */
{
- uint8_t b[4]; /* Byte values. */
- uint16_t h[2]; /* Half word values. */
- uint32_t w; /* Word Value. */
+ uint8_t b[4]; /* Byte values. */
+ uint16_t h[2]; /* Half word values. */
+ uint32_t w; /* Word Value. */
};
-
+
++typedef union xyz_union_u xzy_union_t; ++
The use of typedef'ed unions is acceptable but discouraged.
+
struct xyz_info_s
{
...
@@ -1448,17 +1531,18 @@ struct xyz_info_s
uint8_t b[4]; /* Byte values. */
uint16_t h[2]; /* Half word values. */
uint32_t w; /* Word Value. */
- } u;
+ } u; /* All union fields must be named */
...
};
+
NOTE:
- Note that the union name u is used often.
+ Note that the union fields within structures are often named u.
This is another exception to the prohibition against using single character variable and field names.
- The short field name u clearly identifies a union field and prevents the full name to the union value from being excessively long.
+ The short field name u clearly identifies a union field and prevents the full name of the union value from being excessively long.
Last Updated: April 8, 2017
+Last Updated: April 18, 2017