Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!ncifcrf!lhc!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: portably printing pointers (was Novice MicroSoft C5.1 question) Message-ID: <25995@mimsy.umd.edu> Date: 12 Aug 90 21:31:50 GMT References: <440@demott.COM> <165@srchtec.UUCP> <1906@tkou02.enet.dec.com> <171@srchtec.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 31 In article <171@srchtec.UUCP> johnb@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@cs.umd.edu Path: uunet!mimsy!chris (New campus phone system, active sometime soon: +1 301 405 2750)