Article View: comp.std.c
Article #3513Re: Integral promotion.
From: S. Lee
Date: Wed, 21 Feb 1996 14:13
Date: Wed, 21 Feb 1996 14:13
23 lines
1409 bytes
1409 bytes
In article <4g55fl$avl@solutions.solon.com>, <msb@sq.com> wrote:
>> > short test(short x1, short x2) {
>> > short result;
>> > result = x1 + x2;
>>
>> The addition operator "+" converts your short operands to ints.
>
>No, just using their values does that. The operator + never sees
>operands narrower than int. In the statement
> x1;
>the short is converted to int before being discarded.
Okay, I'm confused. Let just say the above is true. Then the expression
"x1 + x2" has type int because x1 and x2 were converted to int before
being passed to the + operator.
So what if sizeof(short) == sizeof(int)? Assuming both x1 and x2 are
non-negative, would "x1 + x2" be unsigned int if it wouldn't fit in an
int? In short, would there be undefined/implementation defined behaviour
if "result" is unsigned int? How about long?
sl14@cornell.edu
Witty .sig under construction.
Technical Details
Message-ID:
<4gf99c$1fp@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4fstj7$2l6@solutions.solon.com> <4fvgvb$e0t@solutions.solon.com> <4g55fl$avl@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: sl14@crux3.cit.cornell.edu (S. Lee) Newsgroups: comp.std.c,comp.lang.c.moderated Subject: Re: Integral promotion. Date: 21 Feb 1996 08:13:00 -0600 Organization: Nekomi Institute of Technology Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4gf99c$1fp@solutions.solon.com> References: <4fstj7$2l6@solutions.solon.com> <4fvgvb$e0t@solutions.solon.com> <4g55fl$avl@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com