FAQ
How do I refer to a C struct field named 'type', given that 'type' is a
reserved word in Go? For example, in this struct:
struct _GNetSnmpVarBind {
guint32 *oid; /* name of the variable */
gsize oid_len; /* length of the name */
GNetSnmpVarBindType type; /* variable type / exception */
...
};
For example, if the struct is referred to by data,
fmt.Println(data.type) gives:

"expected selector or type assertion, found 'type'"

--
Sonia Hamilton
http://www.snowfrog.net

--
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/groups/opt_out.

Search Discussions

  • Minux at Jan 29, 2013 at 2:44 am

    On Tue, Jan 29, 2013 at 9:42 AM, Sonia Hamilton wrote:

    How do I refer to a C struct field named 'type', given that 'type' is a
    reserved word in Go? For example, in this struct:
    struct _GNetSnmpVarBind {
    guint32 *oid; /* name of the variable */
    gsize oid_len; /* length of the name */
    GNetSnmpVarBindType type; /* variable type /
    exception */
    ...
    };
    For example, if the struct is referred to by data,
    fmt.Println(data.type) gives:

    "expected selector or type assertion, found 'type'
    i think it's impossible to reference that field directly, you'd have to
    call a
    C wrapper function to do that.

    --
    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/groups/opt_out.
  • Sonia Hamilton at Jan 29, 2013 at 4:38 am

    * Sonia Hamilton [2013-01-29 12:42:34 +1100]:

    How do I refer to a C struct field named 'type', given that 'type' is a
    reserved word in Go? For example, in this struct:
    struct _GNetSnmpVarBind {
    guint32 *oid; /* name of the variable */
    gsize oid_len; /* length of the name */
    GNetSnmpVarBindType type; /* variable type / exception */
    ...
    };
    For example, if the struct is referred to by data,
    fmt.Println(data.type) gives:
    Using the power of documentation, one finds [1]:
    Within the Go file, C identifiers or field names that are keywords in
    Go can be accessed by prefixing them with an underscore: if x points
    at a C struct with a field named "type", x._type accesses the field
    [1] http://golang.org/cmd/cgo/

    --
    Sonia Hamilton
    http://www.snowfrog.net

    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 29, '13 at 1:42a
activeJan 29, '13 at 4:38a
posts3
users2
websitegolang.org

2 users in discussion

Sonia Hamilton: 2 posts Minux: 1 post

People

Translate

site design / logo © 2022 Grokbase