This is the mail archive of the gcc-bugs@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]

[Bug c/16775] New: bidmas calculation 64 bit unsigned long long failure


System is Red Hat 9.0
[root@localhost test]# uname -a
Linux localhost 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
[root@localhost test]# gcc --version
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

Complete Sample code to generate failure everytime:
gcc -Wall -o test test.c
---------8<---------8<----  test.c  -----8<---------8<---------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/timeb.h>
#include <errno.h>
#include <sys/time.h>

#define u64 unsigned long long

u64 bad_getms(int add_ms){
        struct timeb tp;
        ftime(&tp);
        return (tp.time * 1000) + tp.millitm + add_ms;  //this line has problem.
}
u64 good_getms(int add_ms){
        struct timeb tp;
        u64 x;
        ftime(&tp);
        x = tp.time;
        x *= 1000;
        x += tp.millitm;
        x += add_ms;
        return x;
}
int main(int argc, char *argv[]){
        u64 good, bad;
        good = good_getms(0);
        bad = bad_getms(0);
        printf("bad is %llu\n", bad);
        printf("good is %llu\n", good);
        if (bad - good < 1000){
                printf("Values are OK\n");
                return 0;
        }
        printf("Values are in error.\n");
        return 1;
}

---------8<---------8<----  test.c  -----8<---------8<---------

sample output
---------8<---------8<----  stdout  -----8<---------8<---------
[root@localhost test]# gcc -Wall -o test test.c
[root@localhost test]# ./test
bad is 18446744073680652190
good is 1090892793758
Values are in error.
[root@localhost test]#
---------8<---------8<----  stdout  -----8<---------8<---------

-- 
           Summary: bidmas calculation 64 bit unsigned long long failure
           Product: gcc
           Version: 3.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Jesse at amvia dot co dot nz
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.2.2
  GCC host triplet: 2.4.20


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16775


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