Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Is this ok?? Keywords: pointer initialization Message-ID: <4934@goanna.cs.rmit.oz.au> Date: 11 Mar 91 06:40:12 GMT References: <1991Mar08.191107.23161@pilikia.pegasus.com> Distribution: comp Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 35 In article <1991Mar08.191107.23161@pilikia.pegasus.com>, art@pilikia.pegasus.com (Art Neilson) set some kind of record for radically incorrect advice about John E. Davis's program #include void fm2(s) char **s; { *s = "Hello\n"; } void fm1(s) char **s; { char *ss; fm2(&ss); *s = ss; } int main() { char *s; fm1(&s); (void) fputs(s,stdout); return(0); } Comrade Neilson ended by writing > You should really read your textbook before posting something like this > to the net. Any book worth it's salt will teach you not to make the > sort of mistakes you've made here. It really is _fitting_ that in advice more appropriately directed at the advisor the very common word "its" is spelled incorrectly. The program works correctly under "gcc -ansi -pedantic" and PCC. The only system-specific thing in it is the "return 0;" in main(). VMS has the convention that a program result signifies success (perhaps with a warning) if it is odd, failure if it is even. Recent versions of DCL have been taught to shut up about the error code 0, precisely to cope with sloppy C code, which may be why some people have reported that it works in VMS. Use EXIT_SUCCESS if you have it, if not #include #ifndef EXIT_SUCCESS #ifdef vms #define EXIT_SUCCESS 1 #else /* not vms */ #define EXIT_SUCCESS 0 #endif /* vms */ #endif /* EXIT_SUCCESS */ exit(EXIT_SUCCESS); /* instead of return 0; */ -- The purpose of advertising is to destroy the freedom of the market.