Im using an 8 byte value and trying to print it out using
printf("%02X\n", variable);
but I can only get 4 bytes to print out how do i print out all 8 bytes
the variable is a pointer (void*)
Im using an 8 byte value and trying to print it out using
printf("%02X\n", variable);
but I can only get 4 bytes to print out how do i print out all 8 bytes
the variable is a pointer (void*)
The printf format specifier %p is specially intended to print pointers.
Otherwise, you could use
%d and %x (and %o) take unsigned integers, I believe. Just as %d can print longs with an extra "l" (lowercase "L"), so can %x and %o. That's my understanding of it, anyway.Code:printf("%02lX\n", variable);
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Last edited by bithub; 08-27-2009 at 11:54 AM.
bit∙hub [bit-huhb] n. A source and destination for information.
Umm . . . yeah, oops. Also, if you're working on Windows, the runtime might not support "ll".
From Common Visual C++ 64-bit Migration IssuesThe %x (hex int format) printf modifier will not work as expected on a 64-bit Windows operating system. It will only operate on the first 32 bits of the value that is passed to it.
* Use %I32x to display an integer on a Windows 32-bit operating system.
* Use %I64x to display an integer on a Windows 64-bit operating system.
* The %p (hex format for a pointer) will work as expected on a 64-bit Windows operating system.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Yeah, %p should be used to print pointer values.
bit∙hub [bit-huhb] n. A source and destination for information.
Agreed. I like how they list the most portable solution last.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
That said, in theory the pointer's value need not be printed out in hexadecimal representation when using the %p format specifier since that detail is implementation defined. Also, in other cases, if the pointer were not a pointer to void, it should be casted to pointer to void when used with %p.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)