🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3522

Re: Integral promotion.

#3522
From: Stan Ryckman
Date: Sat, 24 Feb 1996 15:35
32 lines
1851 bytes
In article <4ggg41$91j@solutions.solon.com>,
Peter Seebach <seebs@solon.com> wrote:
:In article <4ggbcq$81c@solutions.solon.com>,
:Jens M Andreasen  <jens-and@dsv.su.se> wrote:
:>I admit that I am confused too. So in this case the compiler should issue a 
:>warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both 
:>"x" and "1" are promoted to integers, and there could therefore be a 
:>potential loss of precision because "sizeof(int) > sizeof(short)", but no 
:>precision could have been lost if int and short had been the same (small) 
:>size ?? <phew>
:
:x++ is not the same as "x = x + 1".  "++x" nearly is.

However, they *are* all the same in this context (where the value of
the expression is not used, and overflow is impossible).

I think you were confused by the line:
:>warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both 

Note that this was an English "for", not a C "for" since otherwise
there would be () rather than {} around the snippet, which is
the equivalent of {short x=1;}.

I don't think compilers need to issue warnings for potential loss
of precision in any case, though, but I've been wrong before.
And we all know by now that they *may* issue such warnings at any
time without violating the Standard (even for "x *= 2;").

Cheers,
Stan.
--
Stan Ryckman  (stanr@tiac.net) (new e-mail address)
Technical Details
Message-ID: <4gnb8t$bgl@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4ggbcq$81c@solutions.solon.com> <4ggg41$91j@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: stanr@tiac.net (Stan Ryckman)
Newsgroups: comp.std.c,comp.lang.c.moderated
Subject: Re: Integral promotion.
Date: 24 Feb 1996 09:35:57 -0600
Organization: Amber & Sneakers Fan Club
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4gnb8t$bgl@solutions.solon.com>
References: <4ggbcq$81c@solutions.solon.com> <4ggg41$91j@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com