Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!husc6!necntc!cullvax!drw From: drw@cullvax.UUCP (Dale Worley) Newsgroups: comp.lang.c Subject: condition expressions Message-ID: <1221@cullvax.UUCP> Date: Wed, 27-May-87 15:00:16 EDT Article-I.D.: cullvax.1221 Posted: Wed May 27 15:00:16 1987 Date-Received: Sat, 30-May-87 01:54:44 EDT Organization: Cullinet Software, Westwood, MA, USA Lines: 36 levy@ttrdc.UUCP (Daniel R. Levy) writes: > In article <874@cc5.bbn.com.BBN.COM>, keesan@cc5.bbn.com.BBN.COM (Morris M. Keesan) writes: > < In article <801@rtech.UUCP> daveb@rtech.UUCP (Dave Brower) writes: > < < < (expr) ? (double) x : (char)y > < 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." > > Well, this quotation says that the "usual arithmetic conversions" are > performed to bring the expressions to the same type, but it still doesn't > say WHAT type prevails if the two differ; "usual arithmetic conversions" > is begging the question! The type of the result is implicit in the fact that C types that are used in expression computation fall in a linear order int : unsigned int : long int : unsigned long int : double (Under ANSI, float gets stuck in somewhere -- what if float can't accomodate long int?) Thus, given two types, one of them is "bigger" - that's the one that the conditional expression returns. For the example, "char" becomes "int" automatically, and "double" is bigger than that. (In general, you don't need a linear order, only a "join semilattice"; given any two types there is a minimum type that is "bigger" than both of them.) Dale -- Dale Worley Cullinet Software UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw ARPA: cullvax!drw@eddie.mit.edu Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)