News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ Tips: IO - printf, pointers, and pointer-to-members

Started by ben2ong2, October 06, 2006, 11:22:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

(Newsgroups: comp.lang.c++.moderated, 22 Jan 1997)


CRAWFORD: Lee Crawford  <crawford@anubisinc.com>

>>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: You are not allowed to view links. Register or Login (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: You are not allowed to view links. Register or Login (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.


You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login