[PATCH 4/9] CodingStyle: mention "typedef struct S {} S;" if typedef is used
From: Alexey Dobriyan
Date: Fri May 09 2025 - 16:36:29 EST
Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
Documentation/process/coding-style.rst | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
index ac9c1dbe00b7..5c5902a0f897 100644
--- a/Documentation/process/coding-style.rst
+++ b/Documentation/process/coding-style.rst
@@ -443,6 +443,20 @@ EVER use a typedef unless you can clearly match one of those rules.
In general, a pointer, or a struct that has elements that can reasonably
be directly accessed should **never** be a typedef.
+If you must use ``typedef`` consider using identical names for both the type
+and its alias so that the type can be forward declared if necessary:
+
+.. code-block:: c
+
+ typedef struct S { ... } S;
+ typedef union U { ... } U;
+
+ struct S;
+ union U;
+ int f(struct S *s, union U *u);
+
+
+Forward declaring by typedef'ed name doesn't work.
Functions
---------
--
2.49.0