2

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'.

pistach
  • 371
  • 3
  • 18

1 Answers1

4

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.

Bathsheba
  • 220,365
  • 33
  • 331
  • 451