On 12/17/2019 2:22 PM, Segher Boessenkool wrote:
On Tue, Dec 17, 2019 at 01:56:48PM +0100, Vincent Lefevre wrote:
On 2019-12-12 11:53:05 +0100, Josef Wolf wrote:
Thanks for the help, Liu!
This silenced the warning.
The goal should not be to silence warnings, but to write portable
code. If you find a way to silence a warning, only to silence a
warning, this is useless. You'd better disable warnings.
Here your code is still non-portable, perhaps *more* non-portable,
as only conversions between intptr_t and void * are guaranteed to
work. Moreover, the intptr_t type is optional.
Any object pointer, sure (since you can convert those to pointer to
void and back again).
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, 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 ?
Segher