TITLE: printf, pointers, and pointer-to-members (Newsgroups: comp.lang.c++.moderated, 22 Jan 1997) CRAWFORD: Lee Crawford >>You may just be stumbling on pointer to member function >>implementation details. I'm not sure printf() is the best >>way to look at those puppies. HOUGHTON: blair@trojan.neta.com (Blair P Houghton) >I'm sure now it isn't, and my observations have null >value. The "%p" spec, when applied to a pointer-to-member-function, >produces different output every time (on Solaris with Sun C++): CLAMAGE: stephen.clamage@Eng.Sun.COM (Steve Clamage) Pointer-to-member-function is a different category of thing from other kinds of pointers. They are not convertible to any other kind of pointer, for example. Since they must keep track of things like whether the function is virtual, they are normally bigger than an ordinary pointer-to-non-member-function. The "%p" printf modifier is for printing data pointers, so using that modifier to print a pointer-to-member-function is almost certain to print only part of the whole pointer. It might even print unused and uninitialized parts of the object (trash). Finally, consider this: printf("%s %p %d", "the value is", ptr_to_mem_fun, 32); The "%p" modifier says to expect a data pointer on the stack (or however variadic parameters are passed). In fact, a larger object was passed, meaning that the locations where printf expects to find for other parameters will be incorrect. You will not get any valid output.