printing function addresses

Hello everyone;

I've spent a frustrating afternoon trying to figure out how to do something that should be trivial. Namely, printing out the address of a function in C/C++. When I identify the function by its name (no trailing parentheses) using in a COUT expression all I get back is a message to the effect that a function address always equates to logical 1 ("true"). This seems crazy to me since using the function's name should yield its address. I'm using the GCC C++ compiler.

What's the story?

Regards,

Mark Allyn
You will have to cast it to a void*, however keep in mind that sizeof( void* ) is not necessarily the same as the size of any arbitrary function pointer.

EDIT: cast it to an unsigned long I suppose is better.
Last edited on
Hello allynm,

Of course, short name would be better.
Hi jsmith -

Your solution using void ptr cast worked perfectly. Why could I find no documentation on this? Where should I look--

Thanks again.

BTW, why is casting to unsigned long even better?
You would have to look at the member functions provided by the I/O stream object.

I wasn't sure off the top of my head whether casting to a void* would work or not (did not remember if the stream had an overload for a non-char pointer), but I was sure the unsigned long would work.

Either case, you have the same sizeof problem though.


Topic archived. No new replies allowed.