From: Bakul Shah <bakul+plan9@bitblocks.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] BUG!!! in Plan9 compiler!
Date: Thu, 22 Apr 2010 13:07:40 -0700 [thread overview]
Message-ID: <20100422200740.49F7D5B73@mail.bitblocks.com> (raw)
In-Reply-To: Your message of "Thu, 22 Apr 2010 21:32:36 +0200." <20100422193236.GA2388@polynum.com>
On Thu, 22 Apr 2010 21:32:36 +0200 tlaronde@polynum.com wrote:
> On Thu, Apr 22, 2010 at 03:08:40PM -0400, geoff@plan9.bell-labs.com wrote:
> > What type is `smallnumber'?
>
> typedef unsigned char smallnumber;
^^^^^^^^
Aha!
> translated from Pascal:
>
> small_number=0..63;
IIRC in C89 integer promotions rules changed. See 6.3.1.8
(Usual arithmetic conversions)
[Otherwise,]the integer promotions are performed on both
operands. Then the following rules are applied to the
promoted operands:
If both operands have the same type, then no
further conversion is needed.
Otherwise, if both operands have signed integer
types or both have unsigned integer types, the
operand with the type of lesser integer conversion
rank is converted to the type of the operand with
greater rank.
Otherwise, if the operand that has unsigned
integer type has rank greater or equal to the rank
of the type of the other operand, then the operand
with signed integer type is converted to the type
of the operand with unsigned integer type.
>>>> Otherwise, if the type of the operand with signed
integer type can represent all of the values of
the type of the operand with unsigned integer
type, then the operand with unsigned integer type
is converted to the type of the operand with
signed integer type.
Otherwise, both operands are converted to the
unsigned integer type corresponding to the type of
the operand with signed integer type.
Try this on both gcc and 8c (with suitable changes):
#define N(i) atoi(v[i])
int f(int x, int y, unsigned char z) { return (x + y + z) / 2; }
int main(int c, char**v) { printf("%d\n", f(N(1), N(2), N(3))); }
And see what you get.
I suspect you can safely change smallnumber to a signed char
and most likely this particular problem will go away.
next prev parent reply other threads:[~2010-04-22 20:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-22 15:29 tlaronde
2010-04-22 17:03 ` Bakul Shah
2010-04-22 17:36 ` tlaronde
2010-04-22 17:50 ` tlaronde
2010-04-22 19:08 ` geoff
2010-04-22 19:32 ` tlaronde
2010-04-22 20:07 ` Bakul Shah [this message]
2010-04-22 21:15 ` tlaronde
2010-04-22 21:26 ` tlaronde
2010-04-22 22:49 ` Bakul Shah
2010-04-23 7:42 ` tlaronde
2010-04-23 18:53 ` C H Forsyth
2010-04-23 18:51 ` tlaronde
2010-04-23 20:08 ` Bakul Shah
2010-04-23 20:46 ` ron minnich
2010-04-23 21:44 ` erik quanstrom
2010-04-23 22:34 ` erik quanstrom
2010-04-24 18:59 ` Bakul Shah
2010-04-24 21:47 ` Charles Forsyth
2010-04-25 0:31 ` erik quanstrom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100422200740.49F7D5B73@mail.bitblocks.com \
--to=bakul+plan9@bitblocks.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).