[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Bizarre string problem

From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Bizarre string problem
Date: Fri, 10 Sep 2004 09:42:40 +0200 (MET DST)

"Dave Hansen" <address@hidden> wrote:

>    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.


> The way I read this is
>    char t[1] = "Thanks for all the fish.";
> is legal and will initialize the first (and only) element of t to 'T'.

That's the fun about standards. ;-)  The way I read the above is that
this wouldn't be allowed, since the optional clause ``if there is room
in the array'' only applies to the trailing '\0'.

Consequently, GCC at least warns:

% avr-gcc -Wall -S foo.c
foo.c:1: warning: initializer-string for array of chars is too long

whereis it compiles

char t[1] = "T";

without a complaint (to the same assembler code, of cause).

J"org Wunsch                                           Unix support engineer
Wir stellen aus! Auf der SYSTEMS 2004  vom 18.-22. Oktober in München
Halle B 3, Stand 320-206 (Partner-Stand von Sun Microsystems)
Halle B 2, Stand 605 "Die Musterfirma"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]