lkml.org 
[lkml]   [2011]   [Jun]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 1/1] kernel/sched.c: Fix array initialization typo
On Sun, Jun 12, 2011 at 04:01:16PM -0600, Jean Sacren wrote:
> From: Alexey Dobriyan <adobriyan@gmail.com>
> Date: Mon, 13 Jun 2011 00:35:49 +0300
> >
> > On Sun, Jun 12, 2011 at 03:31:07PM -0600, Jean Sacren wrote:
> > > The fix makes certain so that the size of the initialized arrays doesn't
> > > go beyond the boundary set by the array size of 40.
> >
> > Why would it possibly do that?
>
> With that ',' comma, doesn't it imply there might be the 41st element in
> the array?

No, that's not how C works.

> Despite the fact that that element is bogus.

It's not bogus, it's utterly cromulent. Trailing comma on array
initializer was mentioned in the original K&R and is explicitly endorsed
by ISO/IEC 9899:1999 6.7.8 paragraph 1.

> Further, if the comma is there, what's the benefit? I know you're cool,
> but is it cool in code that way as well?
> >
> > And it's not a typo.
>
> What is it then?

It is a standard C idiom for defining array contents. If you write
int x[] = {
1,
2,
3
};

then when I add a fourth element to your array, I have to modify two
lines, and the diff will say
- 3
+ 3,
+ 4
};

whereas if you wrote "3," as the last line of the initializer, the diff
would be one line long.

Furthermore, spot the error in this diff:

@@ -3,4 +3,5 @@ char *x[] = {
"quick",
"brown",
"fox"
+ "jumped"
};
HTH, HAND,
-andy


\
 
 \ /
  Last update: 2011-06-13 01:11    [W:0.071 / U:0.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site