public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: jeroenk@allieddata.com
To: gcc-gnats@gcc.gnu.org
Subject: c/6170: Unsigned division bug in gcc 3.x
Date: Thu, 04 Apr 2002 02:06:00 -0000	[thread overview]
Message-ID: <20020404100333.1093.qmail@sources.redhat.com> (raw)


>Number:         6170
>Category:       c
>Synopsis:       Unsigned division bug in gcc 3.x
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 04 02:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jeroen Kappert
>Release:        gcc version 3.1 20020130 (Red Hat Linux Rawhide 3.1-0.19)
>Organization:
>Environment:
Red Hat Linux 7.2
>Description:
Unsigned division results into incorrect output.

See the following code:

---
#include <stdio.h>

int main(void) {
      signed short int sT = 3;
    unsigned short int uT = 3;
      signed       int sV = sT / 10;
    unsigned       int uV = uT / 10;;

    printf("Signed   division : Value = %d (0x%04X) / 10 = %5d (0x%08X)\n", sT, sT, sV, sV);
    printf("Unsigned division : Value = %u (0x%04X) / 10 = %5u (0x%08X)\n", uT, uT, uV, uV);
    return 0;
}
---

Which results in the following output:
###
Signed   division : Value = 3 (0x0003) / 10 =     0 (0x00000000)
Unsigned division : Value = 3 (0x0003) / 10 =  8191 (0x00001FFF)
###
Note that the signed and unsigned devision differs!

Now I compiled the same code (on another pc) with gcc version: gcc version 2.95.3 20010315 (SuSE)
which gives the following output:
###
Signed   division : Value = 3 (0x0003) / 10 =     0 (0x00000000)
Unsigned division : Value = 3 (0x0003) / 10 =     0 (0x00000000)
###
Note that this is what i expected!

It seems to me that there is a bug in gcc 3.x
>How-To-Repeat:
see description, to repeat the problem.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-04-04 10:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-04  2:06 jeroenk [this message]
2002-04-04  2:35 rth

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=20020404100333.1093.qmail@sources.redhat.com \
    --to=jeroenk@allieddata.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).