C.GoString(nil)

140 views
Skip to first unread message

Vadzim Dambrouski

unread,
Jun 9, 2016, 11:46:12 PM6/9/16
to golang-nuts
Is it a documented feature that passing nil to C.GoString() returns ""? The only clues I've found is this message from Release notes for 2012-02-07
* cgo: accept null pointers in gccgo flavour of C.GoString (thanks Rémy Oudompheng),
And also this code from the standard library that is using this feature (net/cgo_unix.go):
func cgoLookupIPCNAME(name string) (addrs []IPAddr, cname string, err error, completed bool) {
// ...
    if res != nil {
        cname = C.GoString(res.ai_canonname)
        if cname == "" {
            cname = name
        }
        if len(cname) > 0 && cname[len(cname)-1] != '.' {
            cname += "."
        }
    }
// ...
}

Ian Lance Taylor

unread,
Jun 10, 2016, 12:10:04 AM6/10/16
to Vadzim Dambrouski, golang-nuts
On Thu, Jun 9, 2016 at 7:12 PM, Vadzim Dambrouski <pft...@gmail.com> wrote:
>
> Is it a documented feature that passing nil to C.GoString() returns ""?

It is not documented, but it is true, and it is unlikely to change.

Ian
Reply all
Reply to author
Forward
0 new messages