4 ms·
You get error messages if you get it wrong. Spot the bug in the below: // +build windows package my_pkg That's right, if you don't have a newline bet
by TheDong 6y ago
You get error messages if you get it wrong.
Spot the bug in the below:
// +build windows
package my_pkg
That's right, if you don't have a newline between the build comment and the package, it gets ignored as a package doc comment, not a build tag. So that comment is treated as a comment, but if there's a newline it isn't.
If we had a normal pragma, "go build" could error out instead, but we don't.
Similarly, if you typo
//go:embd file
go build will ignore that as a comment. If it were '#embd', the tooling could error out with "unrecognized pragma".
I think that's the main argument for not using comments.