I have some c(++) code that uses sprintf to convert a uint_64 to a string. This needs to be portable to both linux and Solaris.
On linux we use %ju, but there does not appear to be any equivalent on Solaris. The closest I can find is %lu, but this produces incorrect output. Some sample code:
#include <stdio.h> #include <sys/types.h> #ifdef SunOS typedef uint64_t u_int64_t; #endif int main(int argc, char **argv) { u_int64_t val = 123456789123L; #ifdef SunOS printf('%lu\n', val); #else printf('%ju\n', val); #endif }
On linux, the output is as expected; on Solaris 9 (don’t ask), it’s ’28’
What can I use?
If you have have inttypes.h available you can use the macros it provides:
Not pretty (I seem to be saying that a lot recently), but it works.