'Why is there no function pointer conversion specifier to the printf() family functions?
Printing a function pointer can be done in a portable way in a Kernel but I am wondering why the userspace printf() family functions never got the functionality?
Is the reason because it can't be done in a portable way in userspace, the functionality isn't needed (aside from debugging), etc?
I feel like the need to have a %p specifier would apply to a function pointer specifier also?
Solution 1:[1]
While technically undefined behavior, it's a common extension for C compilers to allow conversion from function pointers to object pointers and back. In fact, it's required by POSIX due to dlsym's function signature.
So if you are debugging, you could printf("%p\n", (void *)funptr);. If you are not debugging, take a step back and ask yourself why you need the function's address.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | a3f |
