I'm using Visual Studio 2015 to build a project on 32bit platform and on 64 bit platform.
Sizeof returns an unsigned int in the 32 bit platform and an unsigned __int64 in the 64 bit platform.
I have the following code :
printf ("limit is %u. \n",sizeof(var));
I need to compile the same code on both platforms. Using the format specifier %u gives a warning in 64bit, using %I64u gives a warning in 32bit. Is there a way to use a formatspecifier on both platforms without writing the printf 2 times (with ifdef _WIN32). I have a lot of these warnings in my project. This would be a lot of work and wouldn't look 'clean'.
The type of sizeof is a size_t.
Use %zu as the format specifier for that type. It's guaranteed to be well-defined for all platforms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With