tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] bug


From: Brian Callahan
Subject: Re: [Tinycc-devel] bug
Date: Wed, 8 Jun 2022 14:51:01 +0000

On 6/8/2022 10:03 AM, lrt via Tinycc-devel wrote:
> Find a bug!
> 
> #include <stdio.h>
> #include <math.h>
> #include <time.h>
> 
> int main(int argc, char **argv)
> {
> printf("Hello!\n");
> printf("%lld\n", 641*6700417);
> return 0;
> }
> output:
> Hello!
> 7035757726269441
> 
> Right is :
> Hello!
> 4294967297
> 

No, 4294967297 is not the correct output for this program. Check it
yourself. You'll get this warning with both GCC and Clang:

/home/brian/c $ gcc --version
gcc (GCC) 13.0.0 20220508 (experimental)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

/home/brian/c $ gcc -O2 -o bug bug.c
bug.c: In function 'main':
bug.c:8:29: warning: integer overflow in expression of type 'int'
results in '1' [-Woverflow]
    8 |         printf("%lld\n", 641*6700417);
      |                             ^
/home/brian/c $ ./bug
Hello!
1
/home/brian/c $ tcc --version
tcc version 0.9.27 mob:afc1362 (x86_64 OpenBSD)
/home/brian/c $ tcc -o bug bug.c
/home/brian/c $ ./bug
Hello!
1

If you really want 4294967297 to be output, change 6700417 to 6700417L.
Works with both GCC and TCC.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]