Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Stefan Richter
Jakub Jelinek wrote: > ISO C99 is very obvious in that the terminating '\0' (resp. L'\0') from > the string literal is only added if there is room in the array or if the > array has unknown size. I would say C99 is /explicit/ in this regard. It doesn't seem like an overly /obvious/ language

Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Alexander van Heukelum
On Fri, 3 Aug 2007 00:09:15 +0100, "Al Viro" <[EMAIL PROTECTED]> said: > On Fri, Aug 03, 2007 at 12:51:16AM +0200, Guennadi Liakhovetski wrote: > > On Fri, 3 Aug 2007, Stefan Richter wrote: > > > > > Guennadi Liakhovetski wrote: > > > > with > > > > > > > > char c[4] = "012345"; > > > >

Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Jan Engelhardt
On Aug 3 2007 01:30, Guennadi Liakhovetski wrote: >On Fri, 3 Aug 2007, Al Viro wrote: > >> It doesn't change the fact that use of c[4] or strlen(c) or strcpy(..., c) >> means nasal demon country for you. > >Haha, funny. You, certainly, may think whatever you want, I'm anyway >greatful to you and

Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Bernd Petrovitsch
On Fri, 2007-08-03 at 11:40 +0800, WANG Cong wrote: > On Fri, Aug 03, 2007 at 08:47:56AM +0530, Satyam Sharma wrote: [] > >While we're talking of null-termination of strings, then I bet you > >generally want to be using strlcpy(), really. Often strncpy() isn't > >what you want. Of course, if

Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Bernd Petrovitsch
On Fri, 2007-08-03 at 11:40 +0800, WANG Cong wrote: On Fri, Aug 03, 2007 at 08:47:56AM +0530, Satyam Sharma wrote: [] While we're talking of null-termination of strings, then I bet you generally want to be using strlcpy(), really. Often strncpy() isn't what you want. Of course, if that

Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Jan Engelhardt
On Aug 3 2007 01:30, Guennadi Liakhovetski wrote: On Fri, 3 Aug 2007, Al Viro wrote: It doesn't change the fact that use of c[4] or strlen(c) or strcpy(..., c) means nasal demon country for you. Haha, funny. You, certainly, may think whatever you want, I'm anyway greatful to you and to all

Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Stefan Richter
Jakub Jelinek wrote: ISO C99 is very obvious in that the terminating '\0' (resp. L'\0') from the string literal is only added if there is room in the array or if the array has unknown size. I would say C99 is /explicit/ in this regard. It doesn't seem like an overly /obvious/ language feature

Re: gcc fixed size char array initialization bug - known?

2007-08-03 Thread Alexander van Heukelum
On Fri, 3 Aug 2007 00:09:15 +0100, Al Viro [EMAIL PROTECTED] said: On Fri, Aug 03, 2007 at 12:51:16AM +0200, Guennadi Liakhovetski wrote: On Fri, 3 Aug 2007, Stefan Richter wrote: Guennadi Liakhovetski wrote: with char c[4] = 012345; the compiler warns, but

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Carlo Florendo
Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Randy Dunlap wrote: C99 spec that Al referred you to (available for around US$18 as a pdf) says in 6.7.8, para. 14 (where Al said): "An array of character type may be initialized by a character string literal, optionally enclosed in braces.

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Carlo Florendo
Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Robert Hancock wrote: Because 5 characters will not fit in a 4 character array, even without the null terminator. On Fri, 3 Aug 2007, Stefan Richter wrote: How should gcc know whether you actually wanted that char foo[len] to contain a \0 as

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread WANG Cong
On Fri, Aug 03, 2007 at 08:47:56AM +0530, Satyam Sharma wrote: > > >On Thu, 2 Aug 2007, Jan Engelhardt wrote: > >> On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: >> > [...] >> > >> >struct { >> >char c[4]; >> >int i; >> >} t; >> >t.i = 0x12345678; >> >

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Satyam Sharma
On Thu, 2 Aug 2007, Jan Engelhardt wrote: > On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: > > [...] > > > > struct { > > char c[4]; > > int i; > > } t; > > t.i = 0x12345678; > > strcpy(t.c, c); > > > >and t.i is silently corrupted. Just wanted to ask

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jakub Jelinek
On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: > I've run across the following gcc "feature": > > char c[4] = "01234"; > > gcc emits a nice warning > > warning: initializer-string for array of chars is too long > > But do a > > char c[4] = "0123"; > > and

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Rene Herman
On 08/03/2007 01:26 AM, Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Randy Dunlap wrote: C99 spec that Al referred you to (available for around US$18 as a pdf) says in 6.7.8, para. 14 (where Al said): "An array of character type may be initialized by a character string literal,

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Fri, 3 Aug 2007, Al Viro wrote: > It doesn't change the fact that use of c[4] or strlen(c) or strcpy(..., c) > means nasal demon country for you. Haha, funny. You, certainly, may think whatever you want, I'm anyway greatful to you and to all the rest for the trouble you took to find THE

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Al Viro wrote: > On Fri, Aug 03, 2007 at 12:51:16AM +0200, Guennadi Liakhovetski wrote: >> On Fri, 3 Aug 2007, Stefan Richter wrote: >> >>> Guennadi Liakhovetski wrote: with char c[4] = "012345"; the compiler warns, but actually allocates a 6-byte long array... >>>

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Randy Dunlap wrote: > C99 spec that Al referred you to (available for around US$18 as a pdf) > says in 6.7.8, para. 14 (where Al said): > > "An array of character type may be initialized by a character string literal, > optionally > enclosed in braces. Successive characters

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Fri, Aug 03, 2007 at 12:51:16AM +0200, Guennadi Liakhovetski wrote: > On Fri, 3 Aug 2007, Stefan Richter wrote: > > > Guennadi Liakhovetski wrote: > > > with > > > > > > char c[4] = "012345"; > > > > > > the compiler warns, but actually allocates a 6-byte long array... > > > > Off-topic

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 03:54:34PM -0700, Randy Dunlap wrote: > > > > And, Stefan, there is a perfect way to specify a "0123" without the '\0' - > > {'0', '1', '2', '3'}. > > We are actually a bit beyond traditional K, fwiw. Not in that area - this behaviour is precisely what traditional K had

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Fri, Aug 03, 2007 at 12:36:40AM +0200, Guennadi Liakhovetski wrote: > On Thu, 2 Aug 2007, Robert Hancock wrote: > > > Because 5 characters will not fit in a 4 character array, even without the > > null terminator. > > On Fri, 3 Aug 2007, Stefan Richter wrote: > > > How should gcc know

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Fri, 3 Aug 2007, Stefan Richter wrote: > Guennadi Liakhovetski wrote: > > with > > > > char c[4] = "012345"; > > > > the compiler warns, but actually allocates a 6-byte long array... > > Off-topic here, but: sizeof c / sizeof *c == 4. Don't think it is OT here - kernel depends on gcc.

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Randy Dunlap
On Fri, 3 Aug 2007 00:36:40 +0200 (CEST) Guennadi Liakhovetski wrote: > On Thu, 2 Aug 2007, Robert Hancock wrote: > > > Because 5 characters will not fit in a 4 character array, even without the > > null terminator. > > On Fri, 3 Aug 2007, Stefan Richter wrote: > > > How should gcc know

(off-topic) Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Guennadi Liakhovetski wrote: > Robert, Stefan, I am sorry, I think, you are VERY wrong here. You meant to say "C99 is very wrong". > And, Stefan, there is a perfect way to specify a "0123" without the '\0' - > {'0', '1', '2', '3'}. C99 says char c[4] = "0123"; is a perfect way to say char c[4]

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Robert Hancock wrote: > Because 5 characters will not fit in a 4 character array, even without the > null terminator. On Fri, 3 Aug 2007, Stefan Richter wrote: > How should gcc know whether you actually wanted that char foo[len] to > contain a \0 as last element? Robert,

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Guennadi Liakhovetski wrote: > with > > char c[4] = "012345"; > > the compiler warns, but actually allocates a 6-byte long array... Off-topic here, but: sizeof c / sizeof *c == 4. -- Stefan Richter -=-=-=== =--- ---== http://arcgraph.de/sr/ - To unsubscribe from this list: send the

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Guennadi Liakhovetski wrote: > On Thu, 2 Aug 2007, Andi Kleen wrote: >> 6.7.8.14 of C99: >> `` >> An array of character type may be initialized by a character string literal, >> optionally >> enclosed in braces. Successive characters of the character string literal >> (including the >>

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Robert Hancock
Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Andi Kleen wrote: Guennadi Liakhovetski <[EMAIL PROTECTED]> writes: char c[4] = "0123"; and - a wonder - no warning. It's required by the C standard. 6.7.8.14 of C99: `` An array of character type may be initialized by a character

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Al Viro wrote: > On Thu, Aug 02, 2007 at 10:26:37PM +0200, Guennadi Liakhovetski wrote: > > > > Worse yet, K explicitely writes: > > > > > > > > char pattern[] = "ould"; > > > > is a shorthand for the longer but equivalent > > > > char pattern[] = { 'o', 'u',

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 10:26:37PM +0200, Guennadi Liakhovetski wrote: > > Worse yet, K explicitely writes: > > > > char pattern[] = "ould"; > > is a shorthand for the longer but equivalent > > char pattern[] = { 'o', 'u', 'l', 'd', '\0' }; > > > > In the latter spelling gcc <

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Al Viro wrote: > On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: > > But do a > > > > char c[4] = "0123"; > > > > and - a wonder - no warning. > > And this is a correct behaviour. You get a valid initialier for array; > see 6.7.8[14] for details.

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Andi Kleen wrote: > Guennadi Liakhovetski <[EMAIL PROTECTED]> writes: > > > char c[4] = "0123"; > > and - a wonder - no warning. > > It's required by the C standard. > > 6.7.8.14 of C99: > `` > An array of character type may be initialized by a character string

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: >Hi > >I've run across the following gcc "feature": > > char c[4] = "01234"; > >gcc emits a nice warning > >warning: initializer-string for array of chars is too long > >But do a > > char c[4] = "0123"; > >and - a wonder - no warning.

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Al Viro wrote: > On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: > > But do a > > > > char c[4] = "0123"; > > > > and - a wonder - no warning. > > And this is a correct behaviour. You get a valid initialier for array; > see 6.7.8[14] for details.

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Jesper Juhl wrote: > I believe Guennadi's point is that gcc does not warn about it in the > case of c[4] = "0123"; but only in the case of c[4] = "01234" - so if > we do have such initializations in the kernel we may have some bugs > hiding there that gcc doesn't warn us

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jesper Juhl
On 02/08/07, Al Viro <[EMAIL PROTECTED]> wrote: > On Thu, Aug 02, 2007 at 10:03:03PM +0200, Jesper Juhl wrote: > > I believe Guennadi's point is that gcc does not warn about it in the > > case of c[4] = "0123"; but only in the case of c[4] = "01234" - so if > > we do have such initializations in

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Andi Kleen
Guennadi Liakhovetski <[EMAIL PROTECTED]> writes: > Hi > > I've run across the following gcc "feature": > > char c[4] = "01234"; > > gcc emits a nice warning > > warning: initializer-string for array of chars is too long > > But do a > > char c[4] = "0123"; > and - a wonder - no

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 10:03:03PM +0200, Jesper Juhl wrote: > I believe Guennadi's point is that gcc does not warn about it in the > case of c[4] = "0123"; but only in the case of c[4] = "01234" - so if > we do have such initializations in the kernel we may have some bugs > hiding there that gcc

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: > But do a > > char c[4] = "0123"; > > and - a wonder - no warning. And this is a correct behaviour. You get a valid initialier for array; see 6.7.8[14] for details. Moreover, that kind of code is often quite

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jesper Juhl
On 02/08/07, Jan Engelhardt <[EMAIL PROTECTED]> wrote: > > On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: > >Hi > > > >I've run across the following gcc "feature": > > > > char c[4] = "01234"; > > > >gcc emits a nice warning > > > >warning: initializer-string for array of chars is too

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: >Hi > >I've run across the following gcc "feature": > > char c[4] = "01234"; > >gcc emits a nice warning > >warning: initializer-string for array of chars is too long > >But do a > > char c[4] = "0123"; > >and - a wonder - no warning.

gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
Hi I've run across the following gcc "feature": char c[4] = "01234"; gcc emits a nice warning warning: initializer-string for array of chars is too long But do a char c[4] = "0123"; and - a wonder - no warning. No warning with gcc 3.3.2, 3.3.5, 3.4.5, 4.1.2. I was told

gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
Hi I've run across the following gcc feature: char c[4] = 01234; gcc emits a nice warning warning: initializer-string for array of chars is too long But do a char c[4] = 0123; and - a wonder - no warning. No warning with gcc 3.3.2, 3.3.5, 3.4.5, 4.1.2. I was told 4.2.x does

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: Hi I've run across the following gcc feature: char c[4] = 01234; gcc emits a nice warning warning: initializer-string for array of chars is too long But do a char c[4] = 0123; and - a wonder - no warning. No warning with gcc

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jesper Juhl
On 02/08/07, Jan Engelhardt [EMAIL PROTECTED] wrote: On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: Hi I've run across the following gcc feature: char c[4] = 01234; gcc emits a nice warning warning: initializer-string for array of chars is too long But do a

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: But do a char c[4] = 0123; and - a wonder - no warning. And this is a correct behaviour. You get a valid initialier for array; see 6.7.8[14] for details. Moreover, that kind of code is often quite deliberate.

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 10:03:03PM +0200, Jesper Juhl wrote: I believe Guennadi's point is that gcc does not warn about it in the case of c[4] = 0123; but only in the case of c[4] = 01234 - so if we do have such initializations in the kernel we may have some bugs hiding there that gcc doesn't

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jesper Juhl
On 02/08/07, Al Viro [EMAIL PROTECTED] wrote: On Thu, Aug 02, 2007 at 10:03:03PM +0200, Jesper Juhl wrote: I believe Guennadi's point is that gcc does not warn about it in the case of c[4] = 0123; but only in the case of c[4] = 01234 - so if we do have such initializations in the kernel we

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Andi Kleen
Guennadi Liakhovetski [EMAIL PROTECTED] writes: Hi I've run across the following gcc feature: char c[4] = 01234; gcc emits a nice warning warning: initializer-string for array of chars is too long But do a char c[4] = 0123; and - a wonder - no warning. It's

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Jesper Juhl wrote: I believe Guennadi's point is that gcc does not warn about it in the case of c[4] = 0123; but only in the case of c[4] = 01234 - so if we do have such initializations in the kernel we may have some bugs hiding there that gcc doesn't warn us about.

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: Hi I've run across the following gcc feature: char c[4] = 01234; gcc emits a nice warning warning: initializer-string for array of chars is too long But do a char c[4] = 0123; and - a wonder - no warning. No warning with gcc

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Al Viro wrote: On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: But do a char c[4] = 0123; and - a wonder - no warning. And this is a correct behaviour. You get a valid initialier for array; see 6.7.8[14] for details. Moreover, that

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Andi Kleen wrote: Guennadi Liakhovetski [EMAIL PROTECTED] writes: char c[4] = 0123; and - a wonder - no warning. It's required by the C standard. 6.7.8.14 of C99: `` An array of character type may be initialized by a character string literal, optionally

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Al Viro wrote: On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: But do a char c[4] = 0123; and - a wonder - no warning. And this is a correct behaviour. You get a valid initialier for array; see 6.7.8[14] for details. Moreover, that

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 10:26:37PM +0200, Guennadi Liakhovetski wrote: Worse yet, KR explicitely writes: quote char pattern[] = ould; is a shorthand for the longer but equivalent char pattern[] = { 'o', 'u', 'l', 'd', '\0' }; /quote In the latter spelling gcc 4.2

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Al Viro wrote: On Thu, Aug 02, 2007 at 10:26:37PM +0200, Guennadi Liakhovetski wrote: Worse yet, KR explicitely writes: quote char pattern[] = ould; is a shorthand for the longer but equivalent char pattern[] = { 'o', 'u', 'l', 'd', '\0' };

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Robert Hancock
Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Andi Kleen wrote: Guennadi Liakhovetski [EMAIL PROTECTED] writes: char c[4] = 0123; and - a wonder - no warning. It's required by the C standard. 6.7.8.14 of C99: `` An array of character type may be initialized by a character

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Andi Kleen wrote: 6.7.8.14 of C99: `` An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Guennadi Liakhovetski wrote: with char c[4] = 012345; the compiler warns, but actually allocates a 6-byte long array... Off-topic here, but: sizeof c / sizeof *c == 4. -- Stefan Richter -=-=-=== =--- ---== http://arcgraph.de/sr/ - To unsubscribe from this list: send the line

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Robert Hancock wrote: Because 5 characters will not fit in a 4 character array, even without the null terminator. On Fri, 3 Aug 2007, Stefan Richter wrote: How should gcc know whether you actually wanted that char foo[len] to contain a \0 as last element? Robert,

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Fri, Aug 03, 2007 at 12:51:16AM +0200, Guennadi Liakhovetski wrote: On Fri, 3 Aug 2007, Stefan Richter wrote: Guennadi Liakhovetski wrote: with char c[4] = 012345; the compiler warns, but actually allocates a 6-byte long array... Off-topic here, but: sizeof c /

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Fri, Aug 03, 2007 at 12:36:40AM +0200, Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Robert Hancock wrote: Because 5 characters will not fit in a 4 character array, even without the null terminator. On Fri, 3 Aug 2007, Stefan Richter wrote: How should gcc know whether you

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Randy Dunlap
On Fri, 3 Aug 2007 00:36:40 +0200 (CEST) Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Robert Hancock wrote: Because 5 characters will not fit in a 4 character array, even without the null terminator. On Fri, 3 Aug 2007, Stefan Richter wrote: How should gcc know whether you

(off-topic) Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Guennadi Liakhovetski wrote: Robert, Stefan, I am sorry, I think, you are VERY wrong here. You meant to say C99 is very wrong. And, Stefan, there is a perfect way to specify a 0123 without the '\0' - {'0', '1', '2', '3'}. C99 says char c[4] = 0123; is a perfect way to say char c[4] = {'0',

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Fri, 3 Aug 2007, Stefan Richter wrote: Guennadi Liakhovetski wrote: with char c[4] = 012345; the compiler warns, but actually allocates a 6-byte long array... Off-topic here, but: sizeof c / sizeof *c == 4. Don't think it is OT here - kernel depends on gcc. And, what I

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 03:54:34PM -0700, Randy Dunlap wrote: And, Stefan, there is a perfect way to specify a 0123 without the '\0' - {'0', '1', '2', '3'}. We are actually a bit beyond traditional KR, fwiw. Not in that area - this behaviour is precisely what traditional KR had all

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Thu, 2 Aug 2007, Randy Dunlap wrote: C99 spec that Al referred you to (available for around US$18 as a pdf) says in 6.7.8, para. 14 (where Al said): An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Rene Herman
On 08/03/2007 01:26 AM, Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Randy Dunlap wrote: C99 spec that Al referred you to (available for around US$18 as a pdf) says in 6.7.8, para. 14 (where Al said): An array of character type may be initialized by a character string literal,

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Jakub Jelinek
On Thu, Aug 02, 2007 at 09:55:51PM +0200, Guennadi Liakhovetski wrote: I've run across the following gcc feature: char c[4] = 01234; gcc emits a nice warning warning: initializer-string for array of chars is too long But do a char c[4] = 0123; and - a wonder - no

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Guennadi Liakhovetski
On Fri, 3 Aug 2007, Al Viro wrote: It doesn't change the fact that use of c[4] or strlen(c) or strcpy(..., c) means nasal demon country for you. Haha, funny. You, certainly, may think whatever you want, I'm anyway greatful to you and to all the rest for the trouble you took to find THE quote

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Stefan Richter
Al Viro wrote: On Fri, Aug 03, 2007 at 12:51:16AM +0200, Guennadi Liakhovetski wrote: On Fri, 3 Aug 2007, Stefan Richter wrote: Guennadi Liakhovetski wrote: with char c[4] = 012345; the compiler warns, but actually allocates a 6-byte long array... Off-topic here, but: sizeof c /

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Satyam Sharma
On Thu, 2 Aug 2007, Jan Engelhardt wrote: On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: [...] struct { char c[4]; int i; } t; t.i = 0x12345678; strcpy(t.c, c); and t.i is silently corrupted. Just wanted to ask if this is known,

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread WANG Cong
On Fri, Aug 03, 2007 at 08:47:56AM +0530, Satyam Sharma wrote: On Thu, 2 Aug 2007, Jan Engelhardt wrote: On Aug 2 2007 21:55, Guennadi Liakhovetski wrote: [...] struct { char c[4]; int i; } t; t.i = 0x12345678; strcpy(t.c, c); and t.i is

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Carlo Florendo
Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Robert Hancock wrote: Because 5 characters will not fit in a 4 character array, even without the null terminator. On Fri, 3 Aug 2007, Stefan Richter wrote: How should gcc know whether you actually wanted that char foo[len] to contain a \0 as

Re: gcc fixed size char array initialization bug - known?

2007-08-02 Thread Carlo Florendo
Guennadi Liakhovetski wrote: On Thu, 2 Aug 2007, Randy Dunlap wrote: C99 spec that Al referred you to (available for around US$18 as a pdf) says in 6.7.8, para. 14 (where Al said): An array of character type may be initialized by a character string literal, optionally enclosed in braces.