[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <65271731e25f4_7258329472@dwillia2-xfh.jf.intel.com.notmuch>
Date: Wed, 11 Oct 2023 14:44:17 -0700
From: Dan Williams <dan.j.williams@...el.com>
To: Max Kellermann <max.kellermann@...os.com>, <linux@...ck-us.net>,
<joe@...ches.com>, <gregkh@...uxfoundation.org>,
Jonathan Corbet <corbet@....net>
CC: Max Kellermann <max.kellermann@...os.com>,
<workflows@...r.kernel.org>, <linux-doc@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v3] Documentation/process/coding-style.rst: space around
const
Max Kellermann wrote:
> 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 it.
>
> 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
>
> Link: https://lore.kernel.org/r/264fa39d-aed6-4a54-a085-107997078f8d@roeck-us.net/
> Link: https://lore.kernel.org/r/f511170fe61d7e7214a3a062661cf4103980dad6.camel@perches.com/
> Signed-off-by: Max Kellermann <max.kellermann@...os.com>
> ---
> V1 -> V2: removed "volatile" on gregkh's request.
> V2 -> V3: moved patch changelog below the "---" line
> ---
> Documentation/process/coding-style.rst | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> index 6db37a46d305..71d62d81e506 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -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::
I notice that clang-format reflows that example to:
const void *a;
void *const b;
void **const c;
void *const *const d;
int strcmp(const char *a, const char *b);
...but someone more clang-format savvy than me would need to propose the
changes to the kernel's .clang-format template to match the style
suggestion.
Powered by blists - more mailing lists