Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!linus!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: expr ? ptr : 0 Message-ID: <520@bbncca.ARPA> Date: Mon, 30-Jan-84 11:57:34 EST Article-I.D.: bbncca.520 Posted: Mon Jan 30 11:57:34 1984 Date-Received: Tue, 31-Jan-84 03:23:23 EST Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 36 ---------------------- My C compiler (based on the Ritchie V7 PDP11 C compiler) issues the message "warning: Illegal pointer/integer operation." when expressions such as the above are used, i.e. when one of the operands of the colon in ?: is a pointer and the other is zero. Actually, it gives the same message for any pointer/integer combination, but I'm concerned particularly with 0. The C reference manual says, in section 7.13 (page 191 of K&R), "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." I'm about to fix the compiler to make it recognize the special case of 0, but I'm not sure what "the constant 0" means in the above citation. Should I be concerned only with the case of the integer constant 0? What about the character '\0' and (short)0 and the long 0L? I'd appreciate opinions and empirical results. What do other C compilers out there do with the code main() { int *p, *q, i; p = i ? q : 0; p = i ? q : '\0'; p = i ? q : (short)0; p = i ? q : 0L; } Please send results by mail. Use your own judgement on whether to mail or post opinions. -- Morris M. Keesan {decvax,linus,wjh12}!bbncca!keesan keesan @ BBN-UNIX.ARPA