title: printf with sizeof on 32 vs 64 platforms: how do I handle format code in platform independent manner?
body: <p>I have some code that prints the amount of memory used by the program. The line is similar to this:</p>
  
  <pre><code>printf("The about of RAM used is %u", anIntVariable*sizeof(double) );
  </code></pre>
  
  <p>where anIntVariable is an int variable for the number of elements of the double array. Anyhow, on 32-bit systems I never had any problems but on 64-bit systems, I get a compiler warning about using "%u" for a unsigned long integer. Using "%lu" as the format code fixes the problem on 64-bit but causes the compiler to complain on 32-bit because the type is back to unsigned int. I've found that, indeed, sizeof(double) returns a different value on 32 vs 64 bit systems. I've found some webpage guides to <em>convert</em> code from 32 bit to 64 bit But I'd rather have code that works on both instead of just converting back and forth.</p>
  
  <p>How do I write this line in a platform independent way? I know many ways I could do it using preprocessor directives but that seems like a hack. Surely there's an elegant way that I'm not realizing.</p>