VMS pointer problems continue.
loafman at convex.UUCP
loafman at convex.UUCP
Fri Mar 25 03:08:00 AEST 1988
> /* Written 8:54 pm Mar 23, 1988 by V053MF43 at 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Comp.lang.c
mailing list