Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: multiple assignment to get errno value does not work with 'var' #13930

Closed
yulvil opened this issue Jan 13, 2016 · 2 comments
Closed
Milestone

Comments

@yulvil
Copy link

yulvil commented Jan 13, 2016

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 was expecting var res, err = C.sqrt(1) to work but only res, err := C.sqrt(1) works.

var res, err = C.sqrt(1) fails at compile time with "assignment count mismatch: 2 = 1"

go version go1.6beta1 linux/amd64

Operating System (Virtual Box Guest): Linux 3.16.0-4-amd64 SMP Debian 3.16.7-ckt20-1+deb8u1 (2015-12-14) x86_64 GNU/Linux

Ref golang-nuts: https://groups.google.com/forum/#!topic/golang-nuts/g88yZMHL_A0

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)
}
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Jan 13, 2016
@ianlancetaylor ianlancetaylor changed the title cgo/errno - multiple assignment does not work with 'var' cmd/cgo: multiple assignment to get errno value does not work with 'var' Jan 13, 2016
@mdempsky
Copy link
Member

CL https://golang.org/cl/18623/ mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/18623 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants