Skip to content

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

Closed
@bits01

Description

@bits01
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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions