|
Chris Manghane |
at Sep 2, 2015 at 9:34 pm
|
⇧ |
| |
In this struct, it is a field identified by the blank identifier with a
type size of 0 (the size of an empty struct type). Because the field is the
blank identifier, it cannot be accessed directly; it only serves as a
placeholder. A consequence of this is, as the comment states, unkeyed
literals of ProgInfo cannot be constructued e.g. ProgInfo{1, 2, 3, 4} must
be ProgInfo{Flags: 1, Reguse: 2, Regset: 3, Regindex: 4} or the compiler
will complain that there is a missing field in the struct literal. I'd
imagine this is done to avoid bugs that might arise from specifying the
arguments in an incorrect order.
On Wed, Sep 2, 2015 at 2:11 PM wrote:At
https://go.googlesource.com/go/+/master/src/cmd/internal/obj/link.go#254we have:
type ProgInfo struct {
Flags uint32 // flag bits
Reguse uint64 // registers implicitly used by this instruction
Regset uint64 // registers implicitly set by this instruction
Regindex uint64 // registers used by addressing mode
_ struct{} // to prevent unkeyed literals
}
Could someone explain to me what that "_ struct{}" does? I don't know that
idiom. What is it for?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout. --
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.