The correct portable way to print `int64_t` values is this:
```
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(int argc, char **argv) {
    int64_t a =123, b = 234;
    printf("%" PRId64 " %" PRId64 "\n", a, b);
    return 0;
}
```
Microsoft compilers and libraries may be outdated and force you to use non 
portable alternatives.
Tinycc uses the C library of the host system so if this library does not 
support the format that the macro PRId64 expands to, you may have to use long 
long types:

```
#include <stdio.h>

int main(int argc, char **argv) {
    long long a =123, b = 234;
    printf(“%lld %lld\n", a, b);
    return 0;
}
```

If this still does not work, you have a very old Microsoft C library and you 
should consider upgrading to a more recent system.

Chqrlie.

> On 16 May 2025, at 13:05, avih via Tinycc-devel <tinycc-devel@nongnu.org> 
> wrote:
> 
> No. long is also 32 bit on Windows.
> 
> On Friday, May 16, 2025 at 02:00:54 PM GMT+3, Sun <809935...@qq.com> wrote: 
> 
> Can I use %lu? My os is windows.
> 
> #include <stdio.h>
> #include <inttypes.h>
> 
> int main(int argc, char **argv)
> {
> 
> int64_t a=123,b=234;
> printf("%lu %lu\n",a,b);
> 
> return 0;
> }
> output:
> 123 0
> 
> 
> 
> ------------------ 原始邮件 ------------------
> 发件人: "avih" <avih...@yahoo.com>;
> 发送时间: 2025年5月16日(星期五) 下午5:38
> 收件人: "tinycc-devel"<tinycc-devel@nongnu.org>;
> 抄送: "Sun"<809935...@qq.com>;
> 主题: Re: [Tinycc-devel] find a bug
> 
> I can confirm this output on Windows with mob f10ab130
> (2025-03-28), but only with tcc 32 bit build.
> 
> And, at least on Windows, it also needs #include <inttypes.h>
> 
> However, this program is buggy, because the format %d is for
> int (32 bit on Windows), while the values are 64 bit, so
> a mismatch and undefined behavior is expected.
> 
> The correct C99/POSIX format for 64 bit signed int is PRId64,
> like so: printf("%" PRId64 " %" PRId64 "\n", a, b);
> 
> And using that, the output is correct - 111 and 222.
> 
> Bottom line, the program is buggy, and IMO it's not a bug.
> 
> - avih
> 
> 
> On Friday, May 16, 2025 at 12:20:04 PM GMT+3, Sun via Tinycc-devel 
> <tinycc-devel@nongnu.org> wrote: 
> 
> 
> 
> 
> 
> #include <stdio.h>
> 
> int main(int argc, char **argv)
> {
> int64_t a=111,b=222;
> printf("%d %d\n",a,b);
> 
> return 0;
> }
> output:
> 111 0
> 
> _______________________________________________
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
> 
> _______________________________________________
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to