Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!bbn!cc5.bbn.com!keesan From: keesan@cc5.bbn.com.BBN.COM (Morris M. Keesan) Newsgroups: comp.lang.c Subject: Re: NULL pointers as arguments, really condition expressions Message-ID: <874@cc5.bbn.com.BBN.COM> Date: Mon, 4-May-87 17:21:19 EDT Article-I.D.: cc5.874 Posted: Mon May 4 17:21:19 1987 Date-Received: Sat, 16-May-87 07:38:30 EDT References: <1130@ius2.cs.cmu.edu> <148@nbisos.NBI.COM> <641@gargoyle.UChicago.EDU> <17780@sun.uucp> <801@rtech.UUCP> Reply-To: keesan@cc5.bbn.com.UUCP (Morris M. Keesan) Organization: Bolt Beranek and Newman, Cambridge, MA Lines: 28 Summary: expr ? (double) : (char) is well defined In article <801@rtech.UUCP> daveb@rtech.UUCP (Dave Brower) writes: >Which reminds me of a general problem with the conditional operator. >What is the type of the result of evaluating: > > (expr) ? (double) x : (char)y > >I believe it is undefined. One could adopt a number of possible >rules for interpretation: > > . . . [possible rules omitted for brevity] > >I'm inclined to call it an error. Thoughts, anyone? The type of the expression is well defined. K&R say (7.13, p. 191), "If possible, the usual arithmetic conversions are performed to bring the second and third expressions to a common type." They don't say explicitly that this type is the type of the expression, but that's implicit in the rest of the definition. The Draft Proposed American National Standard is even clearer: "If both . . . have arithmetic type, the usual arithmetic conversions are performed to bring them to the same type and the result has that type." In the example given, the result of the expression is either (double)x or (double)(int)(char)y, following the order of conversions specified by K&R. (Semantics of conversions is not specified as precisely in the DPANS.) -- Morris M. Keesan keesan@cci.bbn.com {harvard,decvax,ihnp4,etc.}!bbnccv!keesan