tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] ?????? bug


From: lrt
Subject: [Tinycc-devel] ?????? bug
Date: Wed, 8 Jun 2022 23:12:27 +0800

int main(int argc, char **argv)
{
printf("Hello!\n");
//uint64_t n = 0xffffffff;
//printf("%lld\n", n);
printf("%lld\n", 0xffff);
printf("%llu\n", 0xffff);
return 0;
}
output:
Hello!
247414872441159679
247414872441159679

Remove comments??different result.


------------------ ???????? ------------------
??????: "Brian Callahan" <bcallah@posteo.net>;
????????: 2022??6??8??(??????) ????10:51
??????: "tinycc-devel"<tinycc-devel@nongnu.org>;
????: "lrt"<809935316@qq.com>;
????: Re: [Tinycc-devel] bug

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]