Newsgroups: comp.lang.c Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps From: flaps@dgp.toronto.edu (Alan J Rosenthal) Subject: Re: VMS pointer problems continue. Message-ID: <8803271803.AA04395@champlain.dgp.toronto.edu> Organization: University of Toronto References: <12602@brl-adm.ARPA> <812@cresswell.quintus.UUCP> <1494@se-sd.sandiego.NCR.COM> Date: Sun, 27 Mar 88 11:03:02 EST Discussing this code: >> char *wr() >> { >> char *b = "Arf!"; >> return(b); >> } rns@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."