Article View: comp.std.c++
Article #3143Re: Incompatibility C++ <-> ANSI-C
From: Steve Clamage
Date: Tue, 30 Jan 1996 17:52
Date: Tue, 30 Jan 1996 17:52
30 lines
1961 bytes
1961 bytes
In article h7q@fsuj01.rz.uni-jena.de, mkt@isun04.inf.uni-jena.de (Tilo Koerbs) writes:
>Does the operator ?: an itegral promotion on its
>second and third operand in C++?
>I cannot find the answer in the ARM. (I think it says: no)
>Consider this:
>char x, y;
>Which type has the following expression:
>(a ? x : y)
>
>In ANSI-C the type is clearly an 'int' (or 'unsigned').
>But the type in C++ is 'char'???
Yes, char. If the second and third operands ('x' and 'y' in the example)
have the same type, that is also the result type. Otherwise the usual
conversions are performed to bring them to a common type. In addition,
if the operands are lvalues, the result is also an lvalue.
These are differences from C. The different rule means that you can
get the expected overloaded function in a call like
foo( B ? x : y );
and that references behave properly. As a side effect, you can also write
(B ? x : y) = 12; // assign 12 to x or y
I'm not sure that is an advantage, however. :-)
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<4elhk6$ai1@engnews1.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<4ekpnj$h7q@fsuj01.rz.uni-jena.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Incompatibility C++ <-> ANSI-C Date: 30 Jan 1996 09:52:47 PST Organization: Sun Microsystems Inc. Approved: austern@isolde.mti.sgi.com Message-ID: <4elhk6$ai1@engnews1.Eng.Sun.COM> References: <4ekpnj$h7q@fsuj01.rz.uni-jena.de> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 30 Jan 1996 16:39:34 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMQ5bAky4NqrwXLNJAQHUdAH/Tq7TLTumpIBlH7ypFUswnPovHKrOc3RM GPGRjfdTcH1TfnZeUQRcyAMyNL1FH0J6XfKyDrxkAXX5dIuy+iUHrg== =uMPv Originator: austern@isolde.mti.sgi.com