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

cgo: C.uchar array or pointer cannot be assigned to uint8 array or pointer #13729

Closed
bits01 opened this issue Dec 25, 2015 · 5 comments
Closed

Comments

@bits01
Copy link

bits01 commented Dec 25, 2015

package main

import "C"

import "fmt"

func main() {
    var cp *C.uchar
    var gop *uint8 = cp
    fmt.Println(gop)

    var carr [1]C.uchar
    var goarr [1]uint8 = carr
    fmt.Println(goarr)
}

Trying to run it:

./main.go:9: cannot use cp (type *C.unsignedchar) as type *uint8 in assignment
./main.go:13: cannot use carr (type [1]C.unsignedchar) as type [1]uint8 in assignment

If I run go tool cgo -godefs it generates a Go file that looks and runs fine:

...
func main() {
        var cp *uint8
        var gop *uint8 = cp
        fmt.Println(gop)

        var carr [1]uint8
        var goarr [1]uint8 = carr
        fmt.Println(goarr)
}

Not sure whether this is the same issue as #13635 that I also reported a few days ago and has been fixed.

Is it possible to land a fix for the above in 1.5.x please?

@minux
Copy link
Member

minux commented Dec 25, 2015 via email

@minux minux closed this as completed Dec 25, 2015
@bits01
Copy link
Author

bits01 commented Dec 25, 2015

I see. I was under the impression that C.uchar works more like the pre-declared byte alias for uint8. Thank you. What confused me was the generated go file when using cgo -godefs

@minux
Copy link
Member

minux commented Dec 25, 2015 via email

@bits01
Copy link
Author

bits01 commented Dec 25, 2015

Thanks for clarifying. I think somewhere in the group or in some post someone recommended to look at the output of cgo -godefs. Lots of conflicting and sometimes misleading info out there.

@bits01
Copy link
Author

bits01 commented Dec 25, 2015

I may have taken what you posted here out of context, sorry.
http://grokbase.com/t/gg/golang-nuts/12cemmrhk5/go-nuts-cgo-cast-c-struct-to-go-struct

@golang golang locked and limited conversation to collaborators Dec 29, 2016
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

3 participants