Differences between version 6 and predecessor to the previous major change of CPortabilityNotes.
Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 6 | Last edited on Saturday, March 26, 2005 7:24:44 pm | by JohnMcPherson | Revert |
Older page: | version 2 | Last edited on Tuesday, January 25, 2005 9:57:02 pm | by PerryLorier | Revert |
@@ -11,13 +11,25 @@
!!!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);
-This however will fail on 64bit machines as uint64_t is "long" not "long long". The best solution
to this that I've
found is to typecast it to the longer of the types and
use that
.
eg:
+</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("%llu
",(long long unsigned)
x);
-Better solutions solicited
.
+ printf("%"PRIu64
,x);
+</verbatim>
+
+----
+Other pages:
+
+* HP has a set of C portability notes [online|http://docs
.hp.com/en/5074/portability.html], although it targets HP-UX.
+* Intel has a similar set of notes [online|http://www.intel.com/cd/ids/developer/asmo-na/eng/technologies/64bit/200519.htm?page=1] (for porting to [ia64] and [amd64])
----
Part of CategoryProgramming