On Wednesday 23 November 2005 07:26, [EMAIL PROTECTED] wrote:

I unreservedly apologise for being utterly wrong:
'what rule says that the scope and lifetime of a string ...'

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