portably printing pointers (was Novice MicroSoft C5.1 question)
Chris Torek
chris at mimsy.umd.edu
Mon Aug 13 07:31:50 AEST 1990
In article <171 at srchtec.UUCP> johnb at srchtec.UUCP (John Baldwin) writes:
>[%p] solves a lot of problems for portability, and I for one am very glad
>I was wrong (I've been grumbling all this time about not being able to
>portably print pointers).
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
(Yes, there is a town in MD called `Avenue'. I made up the other parts
though.)
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
(New campus phone system, active sometime soon: +1 301 405 2750)
More information about the Comp.lang.c
mailing list