Behaviour of %08X format specifiers on addresses
    Graham 
    grahamc001uk at yahoo.co.uk
       
    Sat Sep 22 05:28:09 PDT 2007
    
    
  
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.
    
    
More information about the Digitalmars-d-learn
mailing list