Pointer Trouble Right Here in Unix City

Chris Torek chris at umcp-cs.UUCP
Wed May 29 07:46:11 AEST 1985


?: expressions should have compatible types on both sides of the : part.
For example,

	g(x ? 1.0 : 0)

is legal, with the result of the ?: expression being of type double.
Mixing a pointer to a character and a pointer to a pointer to a character
``ain't strickly kosher''.

The relevant quote from the ANSI draft is:

C.3.15 Conditional operator

Syntax
    conditional-expression:
	logical-OR-expression
	logical-OR-expression ? logical-OR-expression : conditional-expression

Constraints:
   The first operand must have scalar type.  The second and third
operands may each have arithmetic type, or may each have void type, or
may be structure objects, union objects, or pointers that have the same
type.  In addition, one may be a pointer and the other an integral
constant expression with the value 0.

[I left out the semantics description; ``constraints'' covers the
original problem.  The compiler is correct to complain.]
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list