Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
fmt: %*d is too picky about type of length #10732
I am writing a program with a bit buffer and a bit count. For good reasons it makes sense for the count to be something other than int (for example, you're shifting by it a lot, so it makes sense for it to be unsigned).
prints "%!(BADWIDTH)101". http://play.golang.org/p/BGxyBdPV5E
It seems like maybe fmt should allow any integer type for the width. It's a tiny bit more effort in the code and it eliminates an annoyance for users. In my case I didn't know what BADWIDTH meant and at first thought the value was actually bad in some way. It was only when I was about to read the docs that I realized the problem was likely the type.
Don't know how to fix this without adding an allocation to every print. I tried the obvious thing and the test failed:
etc. I believe the problem is that the arrival of reflection causes the argument to escape.
Before the change, given Printf("%x", 3):
go tool 6g -m x.go
After the change:
dunnart=% go tool 6g -m x.go
Without reflection there is no way to handle every integer type. I could handle int and uint but that seems unsatisfactory.