SLUG Mailing List Archives
Re: [SLUG] C Gurus
- To: slug@xxxxxxxxxxx
- Subject: Re: [SLUG] C Gurus
- From: O Plameras <oscarp@xxxxxxxxxxx>
- Date: Wed, 23 Nov 2005 12:18:52 +1100
- User-agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929)
Ian Wienand wrote:
Not confusing if that programmer understands pointers and pointer
On Tue, Nov 22, 2005 at 10:12:07PM +1100, Crossfire wrote:
IIRC, ANSI C 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
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 18.104.22.168
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
well as know and understand that:
1. "variable storage class of static" has a lifetime of the program
which function it is located. By the way this convention is there in
later became ANSI C. In fact, this is one of the very first rules we
learn in Variable
Storage Class Static.
2. An initialised "variable storage class" is static by definition.
3. A function can be typed like any variable storage class.
4. The functionality of "return".