This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/6170: Unsigned division bug in gcc 3.x



>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]