Skip to contentSkip to conversation

Documentation/process/coding-style.rst: space around const

PATCH Superseded Max Kellermann 2 participants 2 messages Oct 10, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Documentation/process/coding-style.rst: space around const

There are currently no rules on the placement of "const", but a recent code submission revealed that there is clearly a preference for spaces around them.

checkpatch.pl has no check at all for this; though it does sometimes complain, but only because it erroneously thinks that the "*" (on local variables) is an unary dereference operator, not a pointer type.

Current coding style for const pointers-to-pointers:

"*const*": 2 occurrences
"* const*": 3
"*const *": 182
"* const *": 681

Just const pointers:

"*const": 2833 occurrences
"* const": 16615

Changed in v2: removed "volatile" on gregkh's request.

---
 Documentation/process/coding-style.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/coding-style.rst +11 -0
index 6db37a46d305..71d62d81e506 100644
@@ -271,6 +271,17 @@ adjacent to the type name.  Examples:
 	unsigned long long memparse(char *ptr, char **retptr);
 	char *match_strdup(substring_t *s);
 
+Use space around the ``const`` keyword (except when adjacent to
+parentheses).  Example:
+
+.. code-block:: c
+
+	const void *a;
+	void * const b;
+	void ** const c;
+	void * const * const d;
+	int strcmp(const char *a, const char *b);
+
 Use one space around (on each side of) most binary and ternary operators,
 such as any of these::
 
Signature · 1 line
2.39.2
#1 lore raw
Quoted 54 lines · Max Kellermann

There are currently no rules on the placement of "const", but a recent code submission revealed that there is clearly a preference for spaces around them.

checkpatch.pl has no check at all for this; though it does sometimes complain, but only because it erroneously thinks that the "*" (on local variables) is an unary dereference operator, not a pointer type.

Current coding style for const pointers-to-pointers:

"*const*": 2 occurrences
"* const*": 3
"*const *": 182
"* const *": 681

Just const pointers:

"*const": 2833 occurrences
"* const": 16615

Changed in v2: removed "volatile" on gregkh's request.

---
 Documentation/process/coding-style.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/coding-style.rst +11 -0
index 6db37a46d305..71d62d81e506 100644
@@ -271,6 +271,17 @@ adjacent to the type name.  Examples:
 	unsigned long long memparse(char *ptr, char **retptr);
 	char *match_strdup(substring_t *s);
 
+Use space around the ``const`` keyword (except when adjacent to
+parentheses).  Example:
+
+.. code-block:: c
+
+	const void *a;
+	void * const b;
+	void ** const c;
+	void * const * const d;
+	int strcmp(const char *a, const char *b);
+
 Use one space around (on each side of) most binary and ternary operators,
 such as any of these::
 
Signature · 1 line
2.39.2

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot