Article View: comp.std.c
Article #3539Re: Integral promotion.
From: msb
Date: Sat, 17 Feb 1996 17:55
Date: Sat, 17 Feb 1996 17:55
35 lines
2024 bytes
2024 bytes
I wrote: > > Thus even in ANSI C, if this function is called this way: > > > > extern short p, q, r, test(short,short); > > r = test(p,q); > > > > the values from p and q are still converted from short to int and back > > to short. Thad Smith (ThadSmith@acm.org) responded: > I find nothing in the Standard that states that the arguments undergo > integral promotions before being assigned to the function parameters. This is in 6.2.1.1/3.2.1.1, the passage which defines the integral promotions. It states that the promotions apply # in an expression wherever an int or unsigned int may be used. Since the call test(1,2) is permissible, this means that p and q must be promoted to int. As noted in my previous posting, they are then converted right back to short within the caller (since a prototype was used), and the compiler can easily optimize this out. Another example of this sort of thing is an assignment expression like p=q, where p and q are short. q is promoted to int, then demoted back to short; since the value cannot change, the compiler optimizes out the conversions. If you write p=(short)q, then the same reason applies to each of the expressions q and (short)q, and you end up with *two* round-trip conversions which should be optimized out. -- Mark Brader, msb@sq.com "Mark is probably right about something, SoftQuad Inc., Toronto but I forget what" -- Rayan Zachariassen My text in this article is in the public domain.
Technical Details
Message-ID:
<4g54pv$ajt@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4fstj7$2l6@solutions.solon.com> <4fu835$9de@solutions.solon.com> <4fvgrm$dv9@solutions.solon.com> <4g28hr$qko@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: msb@sq.com Newsgroups: comp.std.c,comp.lang.c.moderated Subject: Re: Integral promotion. Date: 17 Feb 1996 11:55:11 -0600 Organization: SoftQuad Inc., Toronto, Canada Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4g54pv$ajt@solutions.solon.com> References: <4fstj7$2l6@solutions.solon.com> <4fu835$9de@solutions.solon.com> <4fvgrm$dv9@solutions.solon.com> <4g28hr$qko@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com