Title
Formatted output of function pointers is confusing
Status
nad
Section
[ostream.inserters.arithmetic]
Submitter
Ivan Godard

Created on 2003-10-24.00:00:00 last changed 163 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

This is indeed a wart, but there is no good way to solve it. C doesn't provide a portable way of outputting the address of a function point either.

Date: 2003-10-24.00:00:00

Given:

void f(int) {}
void(*g)(int) = f;
cout << g;

(with the expected #include and usings), the value printed is a rather surprising "true". Rather useless too.

The standard defines:

ostream& operator<<(ostream&, void*);

which picks up all data pointers and prints their hex value, but does not pick up function pointers because there is no default conversion from function pointer to void*. Absent that, we fall back to legacy conversions from C and the function pointer is converted to bool.

There should be an analogous inserter that prints the address of a function pointer.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2637
2003-10-24 00:00:00admincreate