[lkml]   [2007]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: gcc fixed size char array initialization bug - known?
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 actually wanted that char foo[len] to
> > contain a \0 as last element?
> Robert, Stefan, I am sorry, I think, you are VERY wrong here. There is no
> "even" and no guessing. The "string" DOES include a terminating '\0'. It
> is EQUIVALENT to {'s', 't', 'r', 'i', 'n', 'g', '\0'}. And it contains
> SEVEN characters. Please, re-read your K&R. Specifically, the Section
> "Initialization" in the "Function and Program Structure" chapter (section
> 4.9 in my copy), the paragraph about initialization with a string, which I
> quoted in an earlier email.
> 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&R, fwiw.

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 character string literal (including the
terminating null character if there is room or if the array is of unknown size) initialize the
elements of the array."

*** Remember to use Documentation/SubmitChecklist when testing your code ***
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2007-08-03 00:51    [W:0.087 / U:9.092 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site