Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!oresoft!dan From: dan@oresoft.uu.net (Daniel Elbaum) Newsgroups: comp.lang.c++ Subject: Re: type compatibility Keywords: compilers Message-ID: <1989Dec5.014833.8267@oresoft.uu.net> Date: 5 Dec 89 01:48:33 GMT References: <754@gill.UUCP> Reply-To: dan@oresoft.uu.net (Daniel Elbaum) Organization: Oregon Software, Portland, OR Lines: 45 In article <754@gill.UUCP> paul@gill.UUCP (Paul Nordstrom) writes: :While attempting to port InterViews to the Oregon C++ compiler, I came :across the following code (simplified drastically): [simplified even more drastically:] Whitespace(int size, TextData context = SELF); static const void* SELF = (void*)-1; : :Text* Whitespace::Copy () { :#ifdef OREGON : if ( context == this ) : return new Whitespace(size, SELF); : else : return new Whitespace(size, context); :#else : return new Whitespace(size, context==this ? SELF : context); :#endif :} The OREGON code compiles under occ; the conditional expression gives this error: : 27 * return new Whitespace(size, context==this ? SELF : context); : ^203 :*** 203: Error: Operands are of differing or incompatible type The questions: 1) are the two bodies of code equivalent? 2) if so, are they both correct or are they incorrect? One difference between the two fragments is that the first does not impose restriction on the compatibility of |SELF| and |context|, while the second does require that they both be arithmetic types, or a mix of pointers and null constant expressions, or both references, or both of type |void|. In this case the types are both susceptible to conversion to a common type, namely |void*|, so the type of the result will be |void*|. This type is not valid for the return value of the function |Copy()|. -- The disbelievers say: "Lo! This is a mere wizard." -Quran, Surah X ({uunet,tektronix,reed,sun!nosun,osu-cis,psu-cs}!oresoft!(dan)@oresoft.uu.net)