Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
fmt: improve documentation about how verbs work when printing pointers #21409
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
According to the documentation, section 'Format errors', passing a pointer to the %d verb is the case of invalid argument, %d is documented to accept only integers - and it should produce
Can someone please explain to me why adjusting the docs instead of fixing the bug is considered? IMO
Also, for the %d verb to accept pointers looks to me like a C-ism and the OP readily demostrates why it's good that Go avoids them.
AFAICT %d has been supported for pointers since go1.0:
The verbs b, o, x, X are also supported on pointers and not listed explicitly in the pointer section.
We have refrained from changing other behavior in fmt after go1 to avoid breaking code even if it is inconsistent: e.g. byte vs uint8 printing for types and # not always taking into account padding.
This is i think rather a documentation bug than a bug in fmt as go1 code clearly intended these verbs to work on pointers but did not document it.
Therefore, i would suggest we document the support for other verbs than p on pointers more explicitly then removing the b, o, d, x, X verb support for pointers.
this changed the behavior of %d on pointers for go1.1 but did not introduce the %d support for pointers.