On Mon, Mar 11, 2019 at 08:18:01PM +1100, Bruce Evans wrote: > ... > - poor formatting from %p. %p is guaranteed to bad for formatted output. > It is specified to give an (any) implementation-defined sequence of > printing characters. To use it except for low quality debugging > output, not quite as above (the above attempts medium quality, with > some alignment of fields but no attention to field widths for number > values), you first have to know what the implementation defines, > then don't use it when it is unsuitable. It is easiest to never use > it. In FreeBSD, printf(3) documents its format as being as if it > is %#x or %#lx. This gives no control over the field width.
Yeah, this had annoyed me before, I recall some utilities suffer from broken formatting because of %p. > Conversion of pointers to uintmax_t or intmax_t gives full control > over the format, just like for converted integer types. This is not > quite easier and clearer for pointers. 3 casts are needed to go from > an arbitrary pointer to a uintmax_t. First to const volatile void * > (not to plain void *, since that gives cast-qual warnings if the > pointer is const or volatile). Then to uintptr_t. Then to uintmax_t. Thanks for the insight Bruce. ./danfe _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"