Differences between version 5 and previous revision of CPortabilityNotes.
Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 5 | Last edited on Saturday, March 26, 2005 4:33:02 pm | by DanielLawson | Revert |
Older page: | version 4 | Last edited on Saturday, March 26, 2005 4:30:48 pm | by DanielLawson | Revert |
@@ -11,16 +11,20 @@
!!!printf types
!64bitisms and fixed sized types
If you have a fixed sized type (eg, uint64_t) and you want to use printf to display it, you need to know the real type of the integer. eg:
+<verbatim>
uint64_t x;
printf("%llu",x);
+</verbatim>
This however will fail on 64bit machines as uint64_t is "long" not "long long".
POSIX defines some macros to use in this case, normally found in inttypes.h. Eg, for an unsigned 64 bit value, use the macro PRIu64. This will
be substituted for whatever is appropriate on your host - either lu or llu, depending on if you are on a 32bit or 64bit host.eg:
+<verbatim>
uint64_t x;
printf("%"PRIu64,x);
+</verbatim>
----
Other pages: