On Wed Nov 23, 2005 at 09:48:36 +1100, Ian Wienand wrote:
>On Tue, Nov 22, 2005 at 10:12:07PM +1100, Crossfire wrote:
>> IIRC, ANSI C[1] makes no guaranty as to the lifetime of literal
>> strings when their enclosing scope finishes. 
>
>I'm fairly sure ANSI C does, C99 definitely does
>
>> And not all literal strings are 'static' as my code demonstrated.
>
>String literals are defined with static storage duration by
>definition.
>
>C99 6.4.5.5
>
> The multibyte character sequence [string literal] is then used to
> initalize an array of static storage duration and length just
> sufficient to contain the sequence.

Awwesome, that is the clause I was looking for but could not find!

>Where static storage duration is defined in 6.2.4.3
>
> Its lifetime is the entire execution of the program and its stored
> value is initalized only once, prior to program startup.
>
>So it seems quite valid (as you probably know anyway it will be put in
>some read only section which isn't going to go away).  But the code in
>question will have an interesting alternative property that it will
>confuse every single programmer who looks at the code for the rest of
>eternity.

Yeah ;)
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to