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"                 
                                                                   
<[email protected]&gt;;
????????:&nbsp;2022??6??8??(??????) ????10:51
??????:&nbsp;"tinycc-devel"<[email protected]&gt;;
????:&nbsp;"lrt"<[email protected]&gt;;
????:&nbsp;Re: [Tinycc-devel] bug



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

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.&nbsp; 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]
&nbsp;&nbsp;&nbsp; 8 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
printf("%lld\n", 641*6700417);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 ^
/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.
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to