@@ 33,7 33,8 @@ Send questions and feedback to
- [Header files](#header-files)
- [Space placement](#space-placement)
- [Splitting long lines](#splitting-long-lines)
-- [Type declarations](#type-declarations)
+- [Struct and union declarations](#struct-and-union-declarations)
+- [Variable declarations](#variable-declarations)
- [Variable and function naming](#variable-and-function-naming)
## Editor basics
@@ 703,7 704,78 @@ Programmers **SHOULD split long lines with left-right balance.**
Try to make it "look good" by drawing a vertical line at 40 columns and
"balancing" characters on either side. This is a subjective rule.
-## Type declarations
+## Struct and union declarations
+
+Programmers **MUST** declare structs and unions with the `{` on the first line,
+and `};` on its own line.
+
+Correct:
+
+```c
+struct my_struct {
+ int field_a;
+ int field_b;
+ int field_c;
+};
+
+union my_union {
+ int i;
+ long l;
+ double d;
+};
+```
+
+Incorrect:
+
+```c
+struct my_struct
+{
+ int field_a;
+ int field_b;
+ int field_c;
+};
+
+union my_union
+{
+ int i;
+ long l;
+ double d;
+};
+```
+
+Programmers **MUST** place the name of an inline struct or union field on the
+same line as `}` and `;`.
+Correct:
+
+```c
+struct my_struct {
+ struct {
+ int a, b,c;
+ } nested_struct;
+
+ union {
+ int a, b,c;
+ } nested_union;
+};
+```
+
+Incorrect:
+
+```c
+struct my_struct {
+ struct {
+ int a, b,c;
+ }
+ nested_struct;
+
+ union {
+ int a, b,c;
+ }
+ nested_union;
+};
+```
+
+## Variable declarations
Programmers **MUST place \* next to the binding when declaring pointers.**