🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3166

Re: Incompatibility C++ <-> ANSI-C

#3166
From: Mike Ball
Date: Wed, 31 Jan 1996 22:10
40 lines
1689 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'???
> 
> Even different compilers have different results!
> (Borland 3.1: 'char', SPARCompiler 4.0: 'int')

Not in any version of SPARCompiler C++ that I have access to, which is
all of those from 4.0.1 on.  The result is clearly "char".  I don't
have a 4.0 version to check.

The test was

extern "C" printf(const char*, ...);
int i;
int main()
{
    char a = 0;
    char b = 0;
    printf("%d\n", sizeof(i ? a : b));
    return 0;
}

the result was "1"

-Mike-
---
[ 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: <4eo5gl$rik@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <4ekpnj$h7q@fsuj01.rz.uni-jena.de>

Show Full Headers
Complete Article Headers
From: ball@eng.sun.com (Mike Ball)
Message-ID: <4eo5gl$rik@engnews2.Eng.Sun.COM>
X-Original-Date: 31 Jan 1996 16:31:17 GMT
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 31 Jan 96 22:10:04 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: Incompatibility C++ <-> ANSI-C
Organization: Sun Microsystems Inc.
References: <4ekpnj$h7q@fsuj01.rz.uni-jena.de>
Reply-To: ball@eng.sun.com
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMQ/o4eEDnX0m9pzZAQFmkQF+NoBckBu+CQgG/HGwZSsQBW1C5yOWc7DE
 rEKJHrOefFiJRlklzrts8KyU756LYlcL
 =9ETv