[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250509203430.3448-4-adobriyan@gmail.com>
Date: Fri, 9 May 2025 23:34:25 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: corbet@....net
Cc: workflows@...r.kernel.org,
linux-kernel@...r.kernel.org,
Alexey Dobriyan <adobriyan@...il.com>
Subject: [PATCH 4/9] CodingStyle: mention "typedef struct S {} S;" if typedef is used
Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---
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
Powered by blists - more mailing lists