Xref: utzoo comp.os.minix:14429 comp.lang.c:35757 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!ames!vsi1!teda!ditka!kls From: kls@ditka.Chicago.COM (Karl Swartz) Newsgroups: comp.os.minix,comp.lang.c Subject: Re: C SYNTAX QUESTION Message-ID: <34253@ditka.Chicago.COM> Date: 3 Feb 91 23:04:19 GMT References: <43415@nigel.ee.udel.edu> Followup-To: comp.os.minix Organization: Inaction Central, San Jose, California Lines: 65 In article <43415@nigel.ee.udel.edu> HBO043%DJUKFA11.BITNET@cunyvm.cuny.edu (Christoph van Wuellen) writes: >Is this correct, and if so, why? (all but critical fragments deleted) >void void_function(); >i ? void_function() : 0; >In GNU GAS, file obstack.h, many macros of such type are declared, and >my c68/c386 compiler [K&R] complains about that.. >i ? void_function() : (void) 0; >works. For a strictly K&R compiler the question is irrelevant since there is no void type in K&R. If c68/c386 is a "K&R+" compiler, with a few additions such as void, the rules are whatever the compiler writers decided made sense to them. For ANSI C, going by the old draft that I have at hand, the first version of the code (without the cast to void on the third operand) is not legal C. The conditional operator is described in section 3.3.15, with the following constraints: The first operand shall have scalar type. One of the following shall hold for the second and third operands: * both operands have arithmetic type; * both operands have the same structure or union type; * both operands are pointers to the same type; * both operands are pointers to objects that have qualified or unqualified versions of the same type; * both operands have void type; * one operand is a pointer and the other is a null pointer constant; or * one operand is a pointer to an object or incomplete type and the other is a pointer to void. One operand of type void and the other of type int don't meet these constraints. One compiler that I encountered (an older version of VAX-11 C for VMS) didn't even allow a void *result* from a conditional expression, which required a bit of hackery along the lines of: void void_function(); (void) i ? (void_function(), 0) : 0; Blech! -- Karl Swartz |INet kls@ditka.chicago.com 1-408/223-1308 |UUCP {uunet,decwrl}!daver!ditka!kls |Snail 1738 Deer Creek Ct., San Jose CA 95148 "It's psychosomatic. You need a lobotomy. I'll get a saw." (Calvin)