This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.

### 437. Formatted output of function pointers is confusing

Section: 31.7.6.3.2 [ostream.inserters.arithmetic] Status: NAD Submitter: Ivan Godard Opened: 2003-10-24 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [ostream.inserters.arithmetic].

View all issues with NAD status.

Discussion:

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.

Proposed resolution:

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.