Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!think!sam From: sam@think.COM (Sam Kendall) Newsgroups: net.lang.c Subject: Re: expr?(void):(void) Message-ID: <5826@think.COM> Date: Wed, 30-Jul-86 22:01:26 EDT Article-I.D.: think.5826 Posted: Wed Jul 30 22:01:26 1986 Date-Received: Thu, 31-Jul-86 21:12:58 EDT References: <501@bunny.UUCP> <500@copper.UUCP> <273@watmath.UUCP> <1327@ncoast.UUCP> Reply-To: sam@godot.think.com (Sam Kendall) Distribution: net Organization: Thinking Machines, Cambridge, MA Lines: 51 Summary: An example demonstrating that expr?(void):(void) is useful In article <1327@ncoast.UUCP> allbery@ncoast.UUCP (Brandon Allbery) writes: > > [Example in which expr ? f() : g() is used, where f and g return void.] > > That's not a bug, it's a feature. Literally. > > Before you start complaining, consider that the intent of functions returning > (void) is that of: > > #define procedure void > > procedure f1(x, y) { > ... > } This is misleading. Pascal and allied languages have a more restrictive philosphy than C does; yet you are implying that because procedures are allowed only as statements in Pascal, void-valued expressions should be that way in C. void expressions are always allowed as the left operand of the comma operator, and as the first and third expressions in the for statement; should be ban them there, too? More graphically, should we cut off the hands of burglars in the U.S. because it's done that way in Iran? Enough cheap shots. Here is an example of using void in "?:". Suppose you are writing a stdio-like package, and one function has this specification: void PutC(Stream, char); But for efficiency you want to write PutC as a macro. So you define it like this: extern void _WriteBuf(Stream); #define PutC(s, c) (--(s)->count >= 0 ? (void) (*(s)->bufp++ = (c)) \ : _WriteBuf(s, c)) One can also easily come up with examples where void is useful as the right operand of the comma operator, another place where it is illegal in many compilers. As far as I can figure, void is only useful in these contexts within macros, and the reason it is useful there is that you want to make macros syntactically expressions whenever possible, so you need to use whatever control flow you can within expressions. All in all, the ANSI committee did right in allowing void in these places! --- Sam Kendall sam@godot.think.com Thinking Machines Corp. ihnp4!think!sam