[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 Thu, 2 Aug 2007, Andi Kleen wrote:

    > Guennadi Liakhovetski <> writes:
    > > char c[4] = "0123";
    > > and - a wonder - no warning.
    > It's required by the C standard.
    > 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 character if there is room or if the array is of unknown size) initialize the
    > elements of the array.
    > ''
    > Note the "if there is room".
    > I believe the rationale is that it still allows to conveniently initialize
    > non zero terminated strings.

    Right, I accept that it will compile, but I don't understand why "01234"
    produces a warning and "0123" doesn't? Don't think C99 says anything about
    that. And, AFAIU, using structs with fixed-size char array we more or less
    rely on the compiler warning us if anyone initializes it with too long a

    Also interesting, that with

    char c[4] = "012345";

    the compiler warns, but actually allocates a 6-byte long array...

    Guennadi Liakhovetski
    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-02 22:45    [W:0.021 / U:18.368 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site