Path: utzoo!mnetor!uunet!husc6!mit-eddie!bbn!rochester!udel!burdvax!sdcrdcf!otto!convex!authorplaceholder From: loafman@convex.UUCP Newsgroups: comp.lang.c Subject: Re: VMS pointer problems continue. Message-ID: <64400005@convex> Date: 24 Mar 88 17:08:00 GMT References: <12602@brl-adm.ARPA> Lines: 34 Nf-ID: #R:brl-adm.ARPA:-1260200:convex:64400005:000:1163 Nf-From: convex.UUCP!loafman Mar 24 11:08:00 1988 > /* Written 8:54 pm Mar 23, 1988 by V053MF43@ubvmsc.cc.buffalo.EDU */ > /* ---------- "VMS pointer problems continue." ---------- */ > > char *wr(a) > int a; > { > char b = "Arf!"; > > return(b); > } > > main() > { > printf(" %s ",wr(4)); > } > > /* End of text from convex:comp.lang.c */ Actually there ARE a couple of problems: - char b = "..." is attempting to assign a pointer to a character. - char b is an automatic variable. Destroyed when function returns. - wr() returns a pointer. The return(b) returns a char. Garbage. - the printf %s wants a pointer. wr() returns a char not a pointer. Not surprised the thing barfed. Try running lint. I'm surprised the compiler did not complain at great lengths. Most would. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Kenneth W. Loafman @ CONVEX Computer Corp, Dallas, Texas | All opinions Voice: work: (214) 952-0829 home: (214) 964-1250 | are my own, USPSnail: 1705 Coit Rd #2101, Plano, Tx 75075 | of course. UUCP: ihnp4!convex!loafman | CompuServe: 72345,233 | ...KWL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~