I'm writing some 32-bit ANSI C, compiling with gcc
, in which I need to print some 64-bit signed and unsigned integers. The problem is that in gcc
32-bit C, int64_t
and uint64_t
get converted to long long int and unsigned long long int respectively, with format specifier %lld
and %llu
, which are not supported by ANSI C. Using the format specifier macros provided in inttypes.h
don't help either, since those get converted to %lld
and %llu
.
The following code fails to compile:
#include <stdio.h>
#include <inttypes.h>
int main() {
uint64_t some_int = 123456789;
printf("Your int is: %"PRId64"\n", some_int);
return 0;
}
Compiled with gcc main.c -ansi -Og -g -m32 -Wall -Werror -Wextra -pedantic
Error message is:
error: ISO C90 does not support the ‘ll’ gnu_printf length modifier [-Werror=format=]
So, my question is: What format specifier should I use to print double-length integers in 32-bit ANSI C?
uint64_t
was introduced in the C99 standard, there's really no portable way to handle 64-bit integers in older compilers. Why do you want to port it to an older standard? Considering that all three of the big compilers (GCC, Clang and MSVC) now support C99 (and all or most of C11 even) since long back, I don't really see a reason for it. – Some programmer dude