LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Comma at end of enum lists
@ 2008-03-29 17:00 Jacek Luczak
2008-03-29 17:19 ` Mikael Pettersson
2008-03-29 17:20 ` H. Peter Anvin
0 siblings, 2 replies; 15+ messages in thread
From: Jacek Luczak @ 2008-03-29 17:00 UTC (permalink / raw)
To: linux-kernel
Hi All,
I've found that in many enum lists, there's a comma at the end, e.g.
(arch/x86/kernel/early_printk.c):
enum {
MAGIC1 = 0xBACCD00A,
MAGIC2 = 0xCA110000,
XOPEN = 5,
XWRITE = 4,
};
Just out of curiosity, is there any particular reason here (no word in
CodingStyle about that).
-Jacek
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:00 Comma at end of enum lists Jacek Luczak
@ 2008-03-29 17:19 ` Mikael Pettersson
2008-03-29 17:22 ` Jacek Luczak
2008-03-29 18:13 ` Andreas Schwab
2008-03-29 17:20 ` H. Peter Anvin
1 sibling, 2 replies; 15+ messages in thread
From: Mikael Pettersson @ 2008-03-29 17:19 UTC (permalink / raw)
To: Jacek Luczak; +Cc: linux-kernel
Jacek Luczak writes:
> Hi All,
>
> I've found that in many enum lists, there's a comma at the end, e.g.
> (arch/x86/kernel/early_printk.c):
>
> enum {
> MAGIC1 = 0xBACCD00A,
> MAGIC2 = 0xCA110000,
> XOPEN = 5,
> XWRITE = 4,
> };
>
> Just out of curiosity, is there any particular reason here (no word in
> CodingStyle about that).
Yes. This idiom allows you to add or remove items without
changing adjacent lines.
In a language with strict a comma-as-separator rule you can
get this benefit by placing the comma before new items rather
than after existing items:
enum { FOO
,FIE
,FUM
};
but luckily C doesn't need this perversion.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:00 Comma at end of enum lists Jacek Luczak
2008-03-29 17:19 ` Mikael Pettersson
@ 2008-03-29 17:20 ` H. Peter Anvin
2008-03-29 17:25 ` Al Viro
1 sibling, 1 reply; 15+ messages in thread
From: H. Peter Anvin @ 2008-03-29 17:20 UTC (permalink / raw)
To: Jacek Luczak; +Cc: linux-kernel
Jacek Luczak wrote:
> Hi All,
>
> I've found that in many enum lists, there's a comma at the end, e.g.
> (arch/x86/kernel/early_printk.c):
>
> enum {
> MAGIC1 = 0xBACCD00A,
> MAGIC2 = 0xCA110000,
> XOPEN = 5,
> XWRITE = 4,
> };
>
> Just out of curiosity, is there any particular reason here (no word in
> CodingStyle about that).
>
Yes, it's so you can add a line without affecting the line before it,
making a one-line patch into a two-line patch that's more likely to
conflict.
-hpa
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:19 ` Mikael Pettersson
@ 2008-03-29 17:22 ` Jacek Luczak
2008-03-29 18:13 ` Andreas Schwab
1 sibling, 0 replies; 15+ messages in thread
From: Jacek Luczak @ 2008-03-29 17:22 UTC (permalink / raw)
To: Mikael Pettersson; +Cc: linux-kernel
Mikael Pettersson pisze:
> Jacek Luczak writes:
> > Hi All,
> >
> > I've found that in many enum lists, there's a comma at the end, e.g.
> > (arch/x86/kernel/early_printk.c):
> >
> > enum {
> > MAGIC1 = 0xBACCD00A,
> > MAGIC2 = 0xCA110000,
> > XOPEN = 5,
> > XWRITE = 4,
> > };
> >
> > Just out of curiosity, is there any particular reason here (no word in
> > CodingStyle about that).
>
> Yes. This idiom allows you to add or remove items without
> changing adjacent lines.
Yep, that's obvious, one line less in diff after every enum change :)
> In a language with strict a comma-as-separator rule you can
> get this benefit by placing the comma before new items rather
> than after existing items:
>
> enum { FOO
> ,FIE
> ,FUM
> };
>
> but luckily C doesn't need this perversion.
>
I was just curious, because it's not common schema (some miss extra comma).
Thanks,
-Jacek
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:20 ` H. Peter Anvin
@ 2008-03-29 17:25 ` Al Viro
2008-03-29 17:26 ` Jacek Luczak
2008-03-29 17:28 ` H. Peter Anvin
0 siblings, 2 replies; 15+ messages in thread
From: Al Viro @ 2008-03-29 17:25 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Jacek Luczak, linux-kernel
On Sat, Mar 29, 2008 at 10:20:38AM -0700, H. Peter Anvin wrote:
> Jacek Luczak wrote:
> >Hi All,
> >
> >I've found that in many enum lists, there's a comma at the end, e.g.
> >(arch/x86/kernel/early_printk.c):
> >
> >enum {
> > MAGIC1 = 0xBACCD00A,
> > MAGIC2 = 0xCA110000,
> > XOPEN = 5,
> > XWRITE = 4,
> >};
> >
> >Just out of curiosity, is there any particular reason here (no word in
> >CodingStyle about that).
> >
>
> Yes, it's so you can add a line without affecting the line before it,
> making a one-line patch into a two-line patch that's more likely to
> conflict.
Note that doing that makes sense only when you can expect additions to
the end and even then it's a matter of taste.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:25 ` Al Viro
@ 2008-03-29 17:26 ` Jacek Luczak
2008-03-29 17:56 ` Al Viro
2008-03-29 17:28 ` H. Peter Anvin
1 sibling, 1 reply; 15+ messages in thread
From: Jacek Luczak @ 2008-03-29 17:26 UTC (permalink / raw)
To: Al Viro; +Cc: H. Peter Anvin, linux-kernel
Al Viro pisze:
> On Sat, Mar 29, 2008 at 10:20:38AM -0700, H. Peter Anvin wrote:
>> Jacek Luczak wrote:
>>> Hi All,
>>>
>>> I've found that in many enum lists, there's a comma at the end, e.g.
>>> (arch/x86/kernel/early_printk.c):
>>>
>>> enum {
>>> MAGIC1 = 0xBACCD00A,
>>> MAGIC2 = 0xCA110000,
>>> XOPEN = 5,
>>> XWRITE = 4,
>>> };
>>>
>>> Just out of curiosity, is there any particular reason here (no word in
>>> CodingStyle about that).
>>>
>> Yes, it's so you can add a line without affecting the line before it,
>> making a one-line patch into a two-line patch that's more likely to
>> conflict.
>
> Note that doing that makes sense only when you can expect additions to
> the end and even then it's a matter of taste.
>
I think it's hard to ,,expect additions'' or just predict them. But
smaller patch (diff) is one of things that makes sens of adding extra
commas. I'm just pedantic here.
-Jacek
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:25 ` Al Viro
2008-03-29 17:26 ` Jacek Luczak
@ 2008-03-29 17:28 ` H. Peter Anvin
2008-03-29 17:42 ` Jan Engelhardt
2008-03-29 17:52 ` Al Viro
1 sibling, 2 replies; 15+ messages in thread
From: H. Peter Anvin @ 2008-03-29 17:28 UTC (permalink / raw)
To: Al Viro; +Cc: Jacek Luczak, linux-kernel
Al Viro wrote:
> On Sat, Mar 29, 2008 at 10:20:38AM -0700, H. Peter Anvin wrote:
>> Jacek Luczak wrote:
>>> Hi All,
>>>
>>> I've found that in many enum lists, there's a comma at the end, e.g.
>>> (arch/x86/kernel/early_printk.c):
>>>
>>> enum {
>>> MAGIC1 = 0xBACCD00A,
>>> MAGIC2 = 0xCA110000,
>>> XOPEN = 5,
>>> XWRITE = 4,
>>> };
>>>
>>> Just out of curiosity, is there any particular reason here (no word in
>>> CodingStyle about that).
>>>
>> Yes, it's so you can add a line without affecting the line before it,
>> making a one-line patch into a two-line patch that's more likely to
>> conflict.
>
> Note that doing that makes sense only when you can expect additions to
> the end and even then it's a matter of taste.
Yes, it is.
I personally prefer it this way (strongly) for exactly the same reason C
requires a semicolon at the end of each statement, as opposed to Pascal
which doesn't require a semicolon immediately before an "end".
-hpa
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:28 ` H. Peter Anvin
@ 2008-03-29 17:42 ` Jan Engelhardt
2008-03-29 17:52 ` Al Viro
1 sibling, 0 replies; 15+ messages in thread
From: Jan Engelhardt @ 2008-03-29 17:42 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Al Viro, Jacek Luczak, linux-kernel
On Saturday 2008-03-29 18:28, H. Peter Anvin wrote:
>>
>> Note that doing that makes sense only when you can expect additions to
>> the end and even then it's a matter of taste.
>
> Yes, it is.
>
> I personally prefer it this way (strongly) for exactly the same
> reason C requires a semicolon at the end of each statement, as
> opposed to Pascal which doesn't require a semicolon immediately
> before an "end".
...as opposed to Perl which does not strictly require a ; at the
end of a block. :>
# while (1) { print 1; print 2 }
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:28 ` H. Peter Anvin
2008-03-29 17:42 ` Jan Engelhardt
@ 2008-03-29 17:52 ` Al Viro
2008-03-29 17:54 ` H. Peter Anvin
1 sibling, 1 reply; 15+ messages in thread
From: Al Viro @ 2008-03-29 17:52 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Jacek Luczak, linux-kernel
On Sat, Mar 29, 2008 at 10:28:26AM -0700, H. Peter Anvin wrote:
> Yes, it is.
>
> I personally prefer it this way (strongly) for exactly the same reason C
> requires a semicolon at the end of each statement, as opposed to Pascal
> which doesn't require a semicolon immediately before an "end".
enum foo {
Foo,
Bar,
Baz,
Max_foo = Baz
};
when you know there won't any additions past the last line (for that matter,
ending it with
Baz,
Sentry_foo,
Max_foo = Sentry_foo - 1
}; is also an option, in which case the end of enum will never be touched
at all).
enum {Some_constant = ...};
when you do not want to mix it with other constants and use a separate
enum for each natural group.
Sometimes it makes sense, sometimes it doesn't. It is an expressive
element, not something to be cast in stone by Documentation/CodingStyle.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:52 ` Al Viro
@ 2008-03-29 17:54 ` H. Peter Anvin
0 siblings, 0 replies; 15+ messages in thread
From: H. Peter Anvin @ 2008-03-29 17:54 UTC (permalink / raw)
To: Al Viro; +Cc: Jacek Luczak, linux-kernel
Al Viro wrote:
>
> when you know there won't any additions past the last line (for that matter,
> ending it with
> Baz,
> Sentry_foo,
> Max_foo = Sentry_foo - 1
> }; is also an option, in which case the end of enum will never be touched
> at all).
>
Yes, that's a very important exception. Don't put the comma in if you
want the set to be actively closed.
-hpa
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:26 ` Jacek Luczak
@ 2008-03-29 17:56 ` Al Viro
2008-03-29 17:57 ` H. Peter Anvin
0 siblings, 1 reply; 15+ messages in thread
From: Al Viro @ 2008-03-29 17:56 UTC (permalink / raw)
To: Jacek Luczak; +Cc: H. Peter Anvin, linux-kernel
On Sat, Mar 29, 2008 at 06:26:33PM +0100, Jacek Luczak wrote:
> I think it's hard to ,,expect additions'' or just predict them.
Depends on the situation.
> But
> smaller patch (diff) is one of things that makes sens of adding extra
> commas. I'm just pedantic here.
Fine, but please let's not turn that into yet another brainless crusade;
we already have enough of those going...
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:56 ` Al Viro
@ 2008-03-29 17:57 ` H. Peter Anvin
0 siblings, 0 replies; 15+ messages in thread
From: H. Peter Anvin @ 2008-03-29 17:57 UTC (permalink / raw)
To: Al Viro; +Cc: Jacek Luczak, linux-kernel
Al Viro wrote:
> Fine, but please let's not turn that into yet another brainless crusade;
> we already have enough of those going...
Amen!
-hpa
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 17:19 ` Mikael Pettersson
2008-03-29 17:22 ` Jacek Luczak
@ 2008-03-29 18:13 ` Andreas Schwab
2008-03-29 18:24 ` Jan Engelhardt
1 sibling, 1 reply; 15+ messages in thread
From: Andreas Schwab @ 2008-03-29 18:13 UTC (permalink / raw)
To: Mikael Pettersson; +Cc: Jacek Luczak, linux-kernel
Mikael Pettersson <mikpe@it.uu.se> writes:
> In a language with strict a comma-as-separator rule you can
> get this benefit by placing the comma before new items rather
> than after existing items:
>
> enum { FOO
> ,FIE
> ,FUM
> };
>
> but luckily C doesn't need this perversion.
Only since C99 (but GNU C never needed it either).
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 18:13 ` Andreas Schwab
@ 2008-03-29 18:24 ` Jan Engelhardt
2008-03-29 18:47 ` Andreas Schwab
0 siblings, 1 reply; 15+ messages in thread
From: Jan Engelhardt @ 2008-03-29 18:24 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Mikael Pettersson, Jacek Luczak, linux-kernel
On Saturday 2008-03-29 19:13, Andreas Schwab wrote:
>> In a language with strict a comma-as-separator rule you can
>> get this benefit by placing the comma before new items rather
>> than after existing items:
>>
>> enum { FOO
>> ,FIE
>> ,FUM
>> };
>>
>> but luckily C doesn't need this perversion.
>
> Only since C99 (but GNU C never needed it either).
C had this for much longer than 99. Borland Turbo C from around 1990
(which you can expect to be C89 if you have luck) also allows , at the end.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Comma at end of enum lists
2008-03-29 18:24 ` Jan Engelhardt
@ 2008-03-29 18:47 ` Andreas Schwab
0 siblings, 0 replies; 15+ messages in thread
From: Andreas Schwab @ 2008-03-29 18:47 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Mikael Pettersson, Jacek Luczak, linux-kernel
Jan Engelhardt <jengelh@computergmbh.de> writes:
> On Saturday 2008-03-29 19:13, Andreas Schwab wrote:
>>> In a language with strict a comma-as-separator rule you can
>>> get this benefit by placing the comma before new items rather
>>> than after existing items:
>>>
>>> enum { FOO
>>> ,FIE
>>> ,FUM
>>> };
>>>
>>> but luckily C doesn't need this perversion.
>>
>> Only since C99 (but GNU C never needed it either).
>
> C had this for much longer than 99. Borland Turbo C from around 1990
> (which you can expect to be C89 if you have luck) also allows , at the end.
C89 definitely does not allow a comma at the end of the enumerator list
(only at the end of the initializer list). If Borland C allows it in
its strict C89 mode (if it has such a thing) then it is buggy.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2008-03-29 18:47 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-29 17:00 Comma at end of enum lists Jacek Luczak
2008-03-29 17:19 ` Mikael Pettersson
2008-03-29 17:22 ` Jacek Luczak
2008-03-29 18:13 ` Andreas Schwab
2008-03-29 18:24 ` Jan Engelhardt
2008-03-29 18:47 ` Andreas Schwab
2008-03-29 17:20 ` H. Peter Anvin
2008-03-29 17:25 ` Al Viro
2008-03-29 17:26 ` Jacek Luczak
2008-03-29 17:56 ` Al Viro
2008-03-29 17:57 ` H. Peter Anvin
2008-03-29 17:28 ` H. Peter Anvin
2008-03-29 17:42 ` Jan Engelhardt
2008-03-29 17:52 ` Al Viro
2008-03-29 17:54 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).