How to print pointer to function?

Liu Hao lh_mouse@126.com
Thu Dec 12 09:49:00 GMT 2019


在 2019/12/12 17:21, Josef Wolf 写道:
> Hello,
> 
> I would like to print the pointer to a function for debugging purposes.
> 
> But I keep getting a warning:
> 
>   ttt.c: In function 'insert_transfer':
>   ttt.c:7:37: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
>       7 |     printf ("lost transfer %p\r\n", (void*)rdyfunc);
> 
> Is there any way to get rid of this warning?
> 

Casting the point-to-function to `intptr_t` followed by `void*` will
silence the warning:

```
printf ("lost transfer %p\r\n", (void*)(intptr_t)rdyfunc);
```

This may also help if you attempt to cast between different types of
function pointers.


-- 
Best regards,
LH_Mouse

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20191212/67e12482/attachment.sig>


More information about the Gcc-help mailing list