🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1163

Re: Type bug in conditional expressions?

#1163
From: Ron Guilmette
Date: Sat, 15 Sep 1990 21:39
32 lines
1834 bytes
In article <1990Sep12.151529.7268@syd.dit.CSIRO.AU> evans@syd.dit.CSIRO.AU (Bruce.Evans) writes:
>gcc-1.37 on a 386 gives strange results for sizeof on conditional
>expressions.
>
>int a = sizeof (1 ? (char) 1 : (char) 1);	/* 1, wrong? */
>int b = sizeof (1 ? (short) 1 : (short) 1);	/* 2, wrong? */
>int c = sizeof (1 ? (char) 1 : (short) 1);	/* 4, right */
>int d = sizeof (0 ? (char) 1 : (short) 1);	/* 4, right */
>char e, f;
>int g = sizeof (a ? e : f);			/* 1, wrong? */

Even after re-reading section 3.3.3.4 of the ANSI C standard, I can't
figure out what the proper values should be in the cases shown above.

It appears that (contrary to the normal rule about implicit promotions
of char & short expression operands to `int') that there are some special
rules which prevent such promotions when the operands are used as
arguments to sizeof().

Since these *exceptional* rules are never really spelled out very well,
I'm unable to decide what the `right' values for the expressions shown
above are.

Can one of the comp.std.c gurus please say for sure what the `right' values
are?

(Note that the answers may be different in the case of C++.)
-- 

// Ron Guilmette  -  C++ Entomologist
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.
Technical Details
Message-ID: <1606@lupine.NCD.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!swrinde!cs.utexas.edu!uunet!lupine!rfg
References: <1990Sep12.151529.7268@syd.dit.CSIRO.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!swrinde!cs.utexas.edu!uunet!lupine!rfg
From: rfg@NCD.COM (Ron Guilmette)
Newsgroups: gnu.gcc.bug,comp.std.c,comp.std.c++
Subject: Re: Type bug in conditional expressions?
Message-ID: <1606@lupine.NCD.COM>
Date: 15 Sep 90 21:39:59 GMT
References: <1990Sep12.151529.7268@syd.dit.CSIRO.AU>
Followup-To: gnu.gcc.bug
Distribution: gnu
Organization: Network Computing Devices, Inc., Mt. View, CA
Lines: 32