Documentation/process/coding-style.rst: space around const/volatile
Subsystems (2)
PATCH 1/1 Documentation/process/coding-style.rst: space around const/volatile
There are currently no rules on the placement of "const" and "volatile", 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
--- Documentation/process/coding-style.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Documentation/process/coding-style.rst +12 -0
@@ -271,6 +271,18 @@ adjacent to the type name. Examples: unsigned long long memparse(char *ptr, char **retptr); char *match_strdup(substring_t *s); +Use space around the keywords ``const`` and ``volatile`` (except when +adjacent to parentheses). Example: + +.. code-block:: c + + const void *a; + void * const b; + void ** const c; + void * const * const d; + void * volatile e; + 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
Quoted 36 lines · Max Kellermann
There are currently no rules on the placement of "const" and "volatile", 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 *": 681Just const pointers:
"*const": 2833 occurrences
"* const": 16615Signed-off-by Max Kellermann <[email protected]>--- Documentation/process/coding-style.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)Documentation/process/coding-style.rst +1
-0@@ -271,6 +271,18 @@ adjacent to the type name. Examples: unsigned long long memparse(char *ptr, char **retptr); char *match_strdup(substring_t *s); +Use space around the keywords ``const`` and ``volatile`` (except when
Documentation/process/coding-style.rst adjacent to the type name. Examples: · line 284
Quoted 10 lines
Documentation/process/coding-style.rst +10
-0+adjacent to parentheses). Example: + +.. code-block:: c + + const void *a; + void * const b; + void ** const c; + void * const * const d; + void * volatile e; + int strcmp(const char *a, const char *b);
Don't encourage the use of volatile please, it shouldn't be needed in kernel code (hint, almost all uses of it in the tree is wrong except for asm statements and some .h files that know they need it for some hardware operations.)
thanks,
greg k-h
Quoted 1 line · Greg KH
Don't encourage the use of volatile please
I don't mean to - but I figured IF "volatile" is used (for whatever reason, whether correct or not), it should follow the same coding style as "const".
Do you want me to remove mentions of "volatile" (leaving the coding style unspecified), or do you want me to add some warning about using volatile?
Quoted 10 lines · Max Kellermann
Quoted 1 line · Greg KH
Don't encourage the use of volatile please
I don't mean to - but I figured IF "volatile" is used (for whatever reason, whether correct or not), it should follow the same coding style as "const".
Do you want me to remove mentions of "volatile" (leaving the coding style unspecified), or do you want me to add some warning about using volatile?
I would recommend just removing the mentions of it here.
thanks,
greg k-h