3

I've read several articles on this topic, but some say that the way it should be done depends on the architecture and system you're in (Windows/Linux), so is there a proper way to do this platform independent?

3
  • C99 specifies the zu format specifier Commented Dec 25, 2016 at 11:43
  • 1
    I think Microsoft has finally caught up with the standard %zu in VS2015. Commented Dec 25, 2016 at 11:49
  • Use "%zu", "%zo", "%zx", or "%zX" depending on what base you prefer. Commented Dec 25, 2016 at 14:43

1 Answer 1

10

%zu for size_t, with

  • %z for length, and
  • %u for unsigned

Details can be found at

7.21.6.1 The fprintf function

6 The flag characters and their meanings are:

...

z Specifies that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies to a pointer to a signed integer type corresponding to size_t argument.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.