Re: How to print pointer to function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 6.3.2.3 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, 7.20.1.4 specifies intptr_t and uintptr_t for pointers to void
> only, and 6.3.2.3 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 6.3.2.3 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 <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux