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?
Asked
Active
Viewed 1.0k times
2
-
[C99 specifies the `zu` format specifier](http://en.cppreference.com/w/c/io/fprintf) – StoryTeller - Unslander Monica Dec 25 '16 at 11:43
-
1I think Microsoft has *finally* caught up with the standard `%zu` in VS2015. – Paul R Dec 25 '16 at 11:49
-
Use `"%zu"`, `"%zo"`, `"%zx"`, or `"%zX"` depending on what base you prefer. – chux - Reinstate Monica Dec 25 '16 at 14:43
1 Answers
9
%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.