Is this ok??

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Mon Mar 11 16:40:12 AEST 1991


In article <1991Mar08.191107.23161 at pilikia.pegasus.com>,
 art at pilikia.pegasus.com (Art Neilson) set some kind of record for radically
incorrect advice about John E. Davis's program
    #include <stdio.h>
    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 <stdlib.h>
	#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.



More information about the Comp.lang.c mailing list