thanks for "down" answers

Guy Harris guy at auspex.UUCP
Fri Dec 16 04:37:53 AEST 1988


 >It gets worse.  2-3 weeks ago one of my instructors decided to explain
 >fork, exec, and waits.  In all his examples he used wait ( (char *) 0).
 >I pointed out to him that wait wanted an address in which to stuff a result,
 >and using 0 was probably not a good idea.  His reply was 'thats how it is
 >in my manual', after a few minutes of discussion it got upgraded to 'I tried
 >it on my system and it works'.  So, Chris, Doug, and Henry, prepare yourself
 >for 30 or so bright and eager new programmers who will think
 >'wait ((char *) 0)' is the preferred way to do things.

No, if you're not interested in the return status of the process for
which you're waiting, and you're running on a UNIX system more recent
than, say, V6, the preferred way of doing this is

	wait((int *)0)

not

	wait((char *)0)

If the manual says "char *", it's wrong.  (Yes, I know about BSD's
"union wait"; it was a dumb idea, and the BSD *kernel* still thinks it's
supposed to be a pointer to "int".)

Passing a NULL pointer is *not* an error; "wait" treats that as an
indication that it is not to return the exit status.  Aside from the
incorrect data type, your instructor was correct.



More information about the Comp.lang.c mailing list