My company is moving from C slowly to C++98. C++98 is a superset of C so this shouldn't be a problem, but it is. Printing 64-bit fixed-width integers using printf
does not work when used in combination with pedantic, warning flags, and specifying code for a 32-bit environment.
The numbers I need to print are of type uint64_t
. And I understand usage of PRIX64
when using printf
. However, as soon as the extra flags are added when compiling, errors ensue.
I've looked at the headers to see if there's anything weird, but it all looks good. I'm not sure why using this combination works in C but not C++. Of course the correct way to solve this would be to start using std::cout
, but there's so much code to edit, it's not feasible to do it all at once.
Minimal example shown below (print.cpp):
#include <stdio.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
int main()
{
uint64_t num = 0x0;
printf("num is %" PRIX64"\n", num);
return 0;
}
command used to compile it:
g++ print.cpp -o print --std=c++98 -Wall -m32 --pedantic
Expected result: no errors, number is printed. Result:
warning: ISO C++ does not support the ‘ll’ gnu_printf length modifier