FAQ
Hi,

According to the cgo documentation: "Any C function (even void functions)
may be called in a multiple assignment context to retrieve both the return
value (if any) and the C errno variable as an error"

I would like to understand why the multiple assignment works when using
':=' but not when using 'var'. See the code below.

Regards,

PB

Ref: https://golang.org/cmd/cgo/


== main.go ==
package main

/*
#cgo LDFLAGS: -lm
#include <math.h>
*/
import "C"

import "fmt"

func main() {
    res, err := C.sqrt(1) // works
    // var res, err = C.sqrt(1) // assignment count mismatch: 2 = 1
    fmt.Println(res, err)
}


--
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.

Search Discussions

  • Ian Lance Taylor at Jan 13, 2016 at 1:57 am

    On Tue, Jan 12, 2016 at 5:24 PM, PB Côté wrote:
    According to the cgo documentation: "Any C function (even void functions)
    may be called in a multiple assignment context to retrieve both the return
    value (if any) and the C errno variable as an error"

    I would like to understand why the multiple assignment works when using ':='
    but not when using 'var'.
    I'd say it's a bug. Please file it at https://golang.org/issue . Thanks.

    Ian

    --
    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.
  • PB Côté at Jan 13, 2016 at 2:13 am
    Filed https://github.com/golang/go/issues/13930

    Thanks,

    On Tuesday, January 12, 2016 at 5:57:40 PM UTC-8, Ian Lance Taylor wrote:

    On Tue, Jan 12, 2016 at 5:24 PM, PB Côté <pbc...@gmail.com <javascript:>>
    wrote:
    According to the cgo documentation: "Any C function (even void
    functions)
    may be called in a multiple assignment context to retrieve both the return
    value (if any) and the C errno variable as an error"

    I would like to understand why the multiple assignment works when using ':='
    but not when using 'var'.
    I'd say it's a bug. Please file it at https://golang.org/issue .
    Thanks.

    Ian
    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 13, '16 at 1:50a
activeJan 13, '16 at 2:13a
posts3
users2
websitegolang.org

2 users in discussion

PB Côté: 2 posts Ian Lance Taylor: 1 post

People

Translate

site design / logo © 2021 Grokbase