I’m currently improving the part of our COM component that logs all external calls into a file. For pointers we write something like (IInterface*)0x12345678 with the value being equal to the actual address.
Currently no difference is made for null pointers – they are displayed as 0x0 which IMO is suboptimal and inelegant. Changing this behaviour is not a problem at all. But first I’d like to know – is there any real advantage in representing null pointers in hex?
Personally, I’d print
0x0to the log file[*]. Some day when someone comes to parse the file automatically, the more uniform the data is the better. I don’t find0x0difficult to read, so it seems silly to have a special case in the writer code, and another special case in the reader code, for no benefit that I can think of.0x0is preferable to0for grepping the log for NULLs, too: saves you having to figure out that you should be grepping for)0or something funny.I wouldn’t write
0x0for a null pointer constant in C or C++, though. I write non-null addresses so unbelievably rarely that there’s nothing for the nulls to be uniform with. I guess if I was defining a bunch of constants to represent the memory map of some device, and the zero address was significant in that memory map, then I might write it0x0in that context.[*] Or perhaps
0x00000000. I like 32-bit pointers to be printed 8 chars long, because when I read/remember a pointer I start out in pairs from the left. If it turns out to have 7 chars, I get horribly confused at the end ;-). 64-bit pointers it doesn’t matter, because I can’t remember a number that long anyway…