🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Integral promotion

#2078
From: Fergus Henderson
Date: Sat, 30 Sep 1995 14:38
45 lines
2208 bytes
MaxPolk@megaweb.com (Max Polk) writes:

>Note the special treatment given to char and short:
>
>char c;        short s;      int i;        long l;
>c = 'A';       s = 5;        i = 7;        l = 8L;
>c = c + 'B'    s = s + 2;    i = i + 2;    l = l + 2
>ILLEGAL        ILLEGAL       OKAY          OKAY

Excuse me, but where did you get the idea that the first two
examples are illegal?

>Why not allow a char plus a char equal a char, or a short plus 
>a short equal a short, just like an int plus an int DOES equal 
>and int and a long plus a long DOES equal a long.

I agree that this would not be such a bad idea.
However, in defence of the status quo, the above four examples
are all quite legal in C++, so you have not yet demonstrated
any real practical problems arising from the status quo.

>To avoid warnings, you must use a cast:
>c = (char)(c + 'B');        s = (short)(s + 2);
>which is absurdly stupid and unnecessary.

Agreed, but again in defense of the status quo this is a
quality-of-implementation issue.  Such warnings are not
mandated by the standard, and it would certainly be possible
for a C++ compiler to issue warnings about

	int i;
	char c = i;

without issuing warnings in the above cases.
I suggest you send your vendor an enhancement request.

-- 
Fergus Henderson             |  "Australia is the richest country in the world,
fjh@cs.mu.oz.au              |   according to a new system of measuring wealth
http://www.cs.mu.oz.au/~fjh  |   announced by the World Bank yesterday."
PGP: finger fjh@128.250.37.3 |  - Melbourne newspaper "The Age", 18 Sept 1995.
---
[ 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: <9527400.20507@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <MATT.95Sep29001439@Austern>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 30 Sep 95 14:38:07 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Integral promotion
Message-ID: <9527400.20507@mulga.cs.mu.OZ.AU>
Organization: Computer Science, University of Melbourne, Australia
References: <MATT.95Sep29001439@Austern>