On 2025-05-16 13:29:09 +0200, Charlie Gordon wrote:
> 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;
> }
> ```

This is just *a* correct portable way...

> 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;
> }
> ```

The user may keep int64_t, but cast to long long just for the printf:

[...]
   int64_t a =123, b = 234;
   printf("%lld %lld\n", (long long) a, (long long) b);
[...]

This is portable because int64_t necessarily fits in a long long on
any platform.

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)

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

Reply via email to