Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcnc!gatech!hao!ames!ucbcad!ucbvax!decvax!decwrl!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: NULL pointers as arguments, really condition expressions Message-ID: <17965@sun.uucp> Date: Mon, 4-May-87 14:19:27 EDT Article-I.D.: sun.17965 Posted: Mon May 4 14:19:27 1987 Date-Received: Tue, 5-May-87 05:20:49 EDT References: <1130@ius2.cs.cmu.edu> <148@nbisos.NBI.COM> <801@rtech.UUCP> Sender: news@sun.uucp Distribution: na Lines: 56 > What is the type of the result of evaluating: > > (expr) ? (double) x : (char)y > > I believe it is undefined. Well, you're wrong. > One could adopt a number of possible rules for interpretation: > > * Take the type of the true expression as the type of the whole. > * Take the type of the false expression... > * Take the type of the lval, if any. > * Take the type of the "biggest" type of the true or false expr. > * Call it an error. > > I'm inclined to call it an error. Thoughts, anyone? "Take the type of the 'biggest' type of the true or false expr" comes closest to the specified rules. From K&R: 7.13 Conditional operator ...If possible, the usual arithmetic conversions are performed to bring the second and third expressions to a common type; otherwise, if both are pointers of the same type, the result has the common type; otherwise, one must be a pointer and the other the constant 0, and the result has the type of the pointer. and from the October 1, 1986 ANSI C draft: 3.3.15 Conditional operator ... The first operand shall have scalar type. Both the second and third operands may have arithmetic type, or may have the same structure, union, or pointer type, or may be void expressions. In addition, one may be a pointer and the other a null pointer constant, or one may be a pointer to an object and the other a pointer to 'void'. ... If both the second and third operands have arithmetic type, the usual arithmetic conversions are performed to bring them to the same type, and the result has that type. If both the operands have structure, union, or pointer type, the result has that type. If both the operands are void expressions, the result is a void expression. If one of the operands is a pointer to an object and the other is a pointer to 'void', the pointer to an object is converted to type pointer to 'void', and the result has that type. If one operand is a pointer and the other operand a null pointer constant, the result has the type of the pointer.