* kernel style preference trivia: '* const' vs '*const' ?
@ 2022-10-09 16:21 Joe Perches
2022-10-09 16:52 ` Miguel Ojeda
2022-10-10 11:48 ` David Laight
0 siblings, 2 replies; 4+ messages in thread
From: Joe Perches @ 2022-10-09 16:21 UTC (permalink / raw)
To: LKML, linux-doc; +Cc: Miguel Ojeda
The kernel uses '* const' about 10:1 over '*const'
coding_style and checkpatch don't care one way or another.
Does anyone care if there should be some kernel style preference?
$ git grep -P -oh '\b(?:char|u8)\s*\*\s*const\b' -- '*.[ch]' | \
sort | uniq -c | sort -rn
12450 char * const
1357 char *const
41 u8 * const
17 char* const
9 u8 *const
5 char *const
2 char * const
2 char *const
1 char * const
1 char *const
1 char * const
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: kernel style preference trivia: '* const' vs '*const' ?
2022-10-09 16:21 kernel style preference trivia: '* const' vs '*const' ? Joe Perches
@ 2022-10-09 16:52 ` Miguel Ojeda
2022-10-09 21:47 ` Joe Perches
2022-10-10 11:48 ` David Laight
1 sibling, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2022-10-09 16:52 UTC (permalink / raw)
To: Joe Perches; +Cc: LKML, linux-doc
On Sun, Oct 9, 2022 at 6:21 PM Joe Perches <joe@perches.com> wrote:
>
> The kernel uses '* const' about 10:1 over '*const'
Yeah, going with the most commonly used one sounds best.
clang-format will be able to handle either way with
`SpaceAroundPointerQualifiers` as soon as the minimum is LLVM 12.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: kernel style preference trivia: '* const' vs '*const' ?
2022-10-09 16:52 ` Miguel Ojeda
@ 2022-10-09 21:47 ` Joe Perches
0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2022-10-09 21:47 UTC (permalink / raw)
To: Miguel Ojeda; +Cc: LKML, linux-doc
On Sun, 2022-10-09 at 18:52 +0200, Miguel Ojeda wrote:
> On Sun, Oct 9, 2022 at 6:21 PM Joe Perches <joe@perches.com> wrote:
> >
> > The kernel uses '* const' about 10:1 over '*const'
>
> Yeah, going with the most commonly used one sounds best.
>
> clang-format will be able to handle either way with
> `SpaceAroundPointerQualifiers` as soon as the minimum is LLVM 12.
Perhaps the below.
Perhaps it should be a --strict only CHK, but the rest of the const
tests are WARN as well.
---
scripts/checkpatch.pl | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2737e4ced5745..eccd7940eb18b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4605,6 +4605,14 @@ sub process {
}
}
+# check for foo *const, prefer foo * const
+ if ($line =~ /\*const\b/) {
+ if (WARN("POINTER_CONST",
+ "Prefer * const over *const\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\*const\b/* const/;
+ }
+ }
# check for non-global char *foo[] = {"bar", ...} declarations.
if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
WARN("STATIC_CONST_CHAR_ARRAY",
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: kernel style preference trivia: '* const' vs '*const' ?
2022-10-09 16:21 kernel style preference trivia: '* const' vs '*const' ? Joe Perches
2022-10-09 16:52 ` Miguel Ojeda
@ 2022-10-10 11:48 ` David Laight
1 sibling, 0 replies; 4+ messages in thread
From: David Laight @ 2022-10-10 11:48 UTC (permalink / raw)
To: 'Joe Perches', LKML, linux-doc; +Cc: Miguel Ojeda
From: Joe Perches
> Sent: 09 October 2022 17:22
>
> The kernel uses '* const' about 10:1 over '*const'
>
> coding_style and checkpatch don't care one way or another.
>
> Does anyone care if there should be some kernel style preference?
I see a wave of patches to 'correct' all the uses...
> $ git grep -P -oh '\b(?:char|u8)\s*\*\s*const\b' -- '*.[ch]' | \
> sort | uniq -c | sort -rn
> 12450 char * const
> 1357 char *const
> 41 u8 * const
> 17 char* const
That one should be an error.
Consider:
char* const foo, bar;
Fortunately the compiler will find those.
I'd guess 'char* foo' is already an error?
Which makes me think the * ought to be as close as possible
to the variable/field name.
So perhaps 'char *const foo' should be ok.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-10 11:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-09 16:21 kernel style preference trivia: '* const' vs '*const' ? Joe Perches
2022-10-09 16:52 ` Miguel Ojeda
2022-10-09 21:47 ` Joe Perches
2022-10-10 11:48 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox