0

I have a "facade" design pattern for OpenGL calls, which route the calls to their corresponding OpenGL call. I can additionally (but optionally) print out all OpenGL calls and their parameter values, which is useful for debugging. However, for methods which take a GLuint64 parameter (such as glClientWaitSync), I'm unsure which printf formatting to use. I'm specifically targeting Windows with MSVC and Linux with GCC and clang.

  • %lld works with MSVC, but produces warnings with GCC/clang. (warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 6 has type ‘GLuint64 {aka long unsigned int})
  • %lu works with GCC/clang (in x64_86), but and doesn't cause warnings on MSVC. However, it doesn't print correctly (interpreted as a 32-bit integer).

Am I stuck doing an #ifdef for the compiler to make the correct format string, or is there a smarter/easier way to do this?

Note: this is not a duplicate of how to print a int64_t, because GLuint64 is defined as different concrete types at the top of the standard glext.h header.

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
  • 1
    Possible duplicate of [How to print a int64\_t type in C](https://stackoverflow.com/questions/9225567/how-to-print-a-int64-t-type-in-c) – BDL Nov 13 '17 at 21:03
  • 1
    @BDL - see clarification at the bottom, it's not a duplicate. – MuertoExcobito Nov 13 '17 at 21:11
  • It can actually be one of four types: `unsigned long int`, `unsigned long long int`, `unsigned __int64`, `uint64_t`. The duplicate works for all of them on their respective systems. (tested with gcc, clang and vc++). – BDL Nov 13 '17 at 21:34

1 Answers1

2

The answer here is simple: don't.

If you want to printf a GLuint64, then first cast it to a well-defined C++ type, such as unsigned long long. Since the input type is required by the OpenGL specification to be exactly 64-bits in size, and unsigned long long is required by the C specification (and thus by inclusion C++) to be at least 64-bits in size, the conversion should be lossless.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982