RFR: 8292981: Unify and restructure integer printing format specifiers [v2]
Kim Barrett
kbarrett at openjdk.org
Tue Aug 30 00:31:51 UTC 2022
On Mon, 29 Aug 2022 08:22:04 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
> > (And yes we have to cast the ptrs to int using p2i but that is just because of compiler limitations/issues ... which raises the recurring old question of "have we finally reached a point where we can use %p cross-platform?")
>
> One motivation for using PTR_FORMAT instead of %p, is to get consistent output on all platforms. I ran the following on different OSes:
>
> ```
> tty->print_cr("%p " PTR_FORMAT, (void*)0x12345678, (uintptr_t)0x12345678);
> ```
>
> And the result is:
>
> ```
> Linux: 0x12345678 0x0000000012345678
> macOS: 0x12345678 0x0000000012345678
> Win: 0x0000000012345678 0x0000000012345678
> ```
>
> I also tested getting zero padding on Linux, but the compiler informs me that that's not allowed: `error: '0' flag used with '%p' gnu_printf format"`.
The description of "%p" says:
"The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner."
No flag/modifier support is specified for "%p", so using any is UB.
And gcc prints nullptr as "(null)"!
-------------
PR: https://git.openjdk.org/jdk/pull/10042
More information about the hotspot-dev
mailing list