On Jan 19, 1:47 pm, howa <howac...@gmail.comwrote:
In 32 bit pc, I can write
e.g.
char* p1 = "apple";
cout<<(int)p1;
In 64 bit pc, I need to use
char* p1 = "apple";
cout<<(__int64)p1;
(A more portable 64 bit type would be long long.)
What are the cross platform way to so?
cout << static_cast< void* >( p1 ) ;
It's the only way guaranteed to work everywhere.
It doesn't allow you to control the output format in any way,
however. If you need to control the output format, something
like:
cout << static_cast< uintptr_t >( p1 ) ;
will usually work (but uintptr_t is not guaranteed to be present
on a machine where pointers are larger than 64 bits).
If you have to work with an older compiler, which doesn't
support the new integer types, then casting to size_t is often
OK (although I've used platforms where it wouldn't work).
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique oriente objet/
Beratung in objektorientierter Datenverarbeitung
9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34