digitalmars.D.learn - Behaviour of %08X format specifiers on addresses
- Graham (41/41) Sep 22 2007 Being used to printing addresses in "C" as 8 hex digits I though the beh...
- Graham (4/4) Sep 22 2007 I realize that the documentation says that the argument should be an int...
- Jarrett Billingsley (5/12) Sep 22 2007 Try using
Being used to printing addresses in "C" as 8 hex digits I though the behavior of this code a little unexpected: import std.stdio; void main(char[][] args) { char* p; int n; p = cast(char*) 1; writefln("p = %08X", p); n = 1; writefln("n = %08X", n); p = cast(char*) 0x12; writefln("p = %08X", p); n = 0x12; writefln("n = %08X", n); p = cast(char*) 0x1234; writefln("p = %08X", p); n = 0x1234; writefln("n = %08X", n); p = cast(char*) 0x123456; writefln("p = %08X", p); n = 0x123456; writefln("n = %08X", n); p = cast(char*) 0x12345678; writefln("p = %08X", p); n = 0x12345678; writefln("n = %08X", n); } which displays: p = 0001 n = 00000001 p = 0012 n = 00000012 p = 1234 n = 00001234 p = 123456 n = 00123456 p = 12345678 n = 12345678 I presume this is intentional (not always displaying the leading zeros on addresses). Is it documented anywhere that this is how it should behave ? I am running the v1.015 compiler on a Windows platform.
Sep 22 2007
I realize that the documentation says that the argument should be an integer type when using %X etc. format specifiers, so it works as I expected with writefln("p = %08X", cast(int)p); etc. But even so accepting a non-integer type and then supposing small values are only 16 bits seems a bit odd.
Sep 22 2007
"Graham" <grahamc001uk yahoo.co.uk> wrote in message news:fd32ak$255t$1 digitalmars.com...I realize that the documentation says that the argument should be an integer type when using %X etc. format specifiers, so it works as I expected with writefln("p = %08X", cast(int)p); etc. But even so accepting a non-integer type and then supposing small values are only 16 bits seems a bit odd.Try using writefln("p = %08p", p); It might even just be "%p".
Sep 22 2007