How to print pointer to function?

Vincent Lefevre
Tue Dec 17 16:30:00 GMT 2019

On 2019-12-17 16:27:28 +0100, Manfred wrote:
> On 12/17/2019 2:22 PM, Segher Boessenkool wrote:
> > Is there *any* portable way to print function pointers?  Other than
> > accessing it as bytes :-)
> n1570 section p6 says "Any pointer type may be converted to an
> integer type. Except as previously specified, the result is
> implementation-defined. ..."
> It says implementation-defined, not undefined,

IMHO, the difference matters mainly for the implementer: in short,
he must not ignore the issue. But an implementation-defined behavior
(or result) can be almost as useless as undefined behavior.

> so AFAIU it is legal, although you can't make assumptions on the
> actual value of the result.
> However, specifies intptr_t and uintptr_t for pointers to void
> only, and p1 specifies the conversion to/from pointers to void and
> pointers to "any object type" which does not include functions, AFAIU.
> So, unless I am missing something, there seems indeed to be a broken link in
> the chain from pointer to function to (u)intptr_t.
> But then what's the purpose of p6 ?

I would have actually preferred undefined behavior with a diagnostic.
I'm wondering why a programmer would want to convert a pointer to an
integer (except as a workaround to bizarre limitations, which would
better be solved directly by the standard).

Vincent Lefèvre <> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the Gcc-help mailing list