Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!im4u!ut-sally!seismo!cmcl2!philabs!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: is a void function invocation an expression or a statement? Message-ID: <502@dg_rtp.UUCP> Date: Wed, 6-Aug-86 16:57:43 EDT Article-I.D.: dg_rtp.502 Posted: Wed Aug 6 16:57:43 1986 Date-Received: Sat, 9-Aug-86 05:31:22 EDT References: <501@bunny.UUCP> <500@copper.UUCP> <273@watmath.UUCP> Lines: 53 Summary: It's an expression, and I can prove it, see? > From: aka@cbrma.UUCP (Andy Kashyap) > A function call is an expression and can, therefore, be used anywhere an > expression can be used. When you declare a function (void), you state that > you intend to use that function as a statement instead, that you do not > intend to use it in any operations. It can now only be used where a statement > can. Keep in mind that an expression is a statement, but NOT vice-versa. Not quite the case at all. When you declare a function void, you are saying that its evaluation yields a void expression. You are *NOT* saying that it is a statement. Again, let us consult Holy Writ on the subject. First, K&R have nothing to say about this, since void didn't exist then. Harbison and Steele say (on page 150): The type of the function expression must be "function returning T" for some type T, in which case the result of the function call is of type T. The result is not an lvalue. If T is void, however, then the function call produces no result and may not be used in a context that requires the call to yield a result. That is, function invocations are *ALWAYS* expressions. Sometimes, these expressions are void, that is, they have no value. Clear enough. Now let's see what the ANSI C draft standard has to say (in 2.2.2): The (nonexistent) value of a *void* *expression* (an expression that has type void) shall not be used in any way, and explicit or implicit conversions shall not be applied to such an expression. (and in 3) An *expression* is a sequence of operators and operands that specifies how to compute a value, or (in the case of a void expression) how to generate side effects. Again, fairly clear. Void "thingies" (how's that for a technical term, eh?) are expressions, and *NOT* statements. (That is, not statements except in the sense that all expressions are statements in C, right?) The only surprising thing here is that not all expressions return values when they are evaluated. But this "surprise" in implicit in the meaning of "voidness". (As a small nit, I'd druther that the draft standard would allow a void expression to be cast to void, but that's a fairly small quibble.) -- There are some forms of insanity which, driven to an ultimate expression, can become the new models of sanity. --- Bureau of Sabotage {Frank Herbert} -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw