portably printing pointers (was Novice MicroSoft C5.1 question)

Colin Plumb colin at array.UUCP
Wed Aug 15 09:16:53 AEST 1990


In article <25995 at mimsy.umd.edu> chris at mimsy.umd.edu (Chris Torek) writes:
-> Although ANSI says that `%p' prints a pointer (of type `void *') and thus
-> this is in a sense `portable', it also goes on to say `in an implementation-
-> defined manner', so in another sense this is not anywhere near portable.
-> One possible manner for printing a pointer would be to print a mailing
-> address for one house/apartment/whatever somewhere in the world, with
-> a different (and unique) address for each possible pointer value.
->
->	printf("%p %p %p", (void *)ptr1, (void *)ptr2, (void *)ptr3);
->
-> might produce
->
->	9191 Farrel Avenue
->	Columbus, OH
->
->	12500 Lakeshore Drive
->	Chicago, IL
->
->	17 Ashburn Pl
->	Avenue, MD

I'd like to suggest to implementors, though, that %p not produce
strings containing characters for which isprint() is false.
Doing so makes things like "% 10p" very hard to use.  Indeed,
isgraph() is probably advisable, to allow the bounds of the pointer's
printed form to be delimited by whitespace.

(I would go so far as to suggest that ANSI would have codified it,
had anyone raised the possibility at the appropriate time.)
-- 
	-Colin



More information about the Comp.lang.c mailing list