VMS pointer problems continue.

Alan J Rosenthal flaps at dgp.toronto.edu
Mon Mar 28 02:03:02 AEST 1988


Discussing this code:

>> char *wr()
>> {
>>     char *b = "Arf!";
>>     return(b);
>> }

rns at se-sd.sandiego.NCR.COM (Rick Schubert) writes:

>The string pointed to by b ("Arf!") should be considered local to
>wr(); the compiler is free to allocate it on the stack ...  Thus the
>value returned from wr() is a pointer to storage that is no longer in
>scope (i.e. may be in an obsolete stack frame).

Blatantly false!  K&R, page 181, section 2.5:
	A string has type ``array of characters'' and storage class static
	(see \S4 below) and is initialized with the given characters.
[ the `\S' means a section reference symbol ]

>From the 11 January 1988 ANSI C Draft, section 3.1.4, page 31, line 25:
	A character string literal has static storage duration and type
	``array of char,'' and is initialized with the given characters.
[ they put that comma inside the quotes, not me ]

Now, there may be compilers that do what you say, but (all together now)
THAT AIN'T C.

ajr
-- 
"Comment, Spock?"
"Very bad poetry, Captain."




More information about the Comp.lang.c mailing list