-
Notifications
You must be signed in to change notification settings - Fork 18k
cgo: C.uchar array or pointer cannot be assigned to uint8 array or pointer #13729
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
Comments
This is working as intended.
uint8 and C.uchar are not the same type,
according to the Go rules.
You can think of C.uchar as
type C.uchar uint8
Because it's a named type whose underlying type is uint8,
the type is different from uint8.
As an example, even this won't compile for the same reason:
var c1 C.uchar
var c2 uint8 = c1
|
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 output is not the file generated for cgo,
it's used to generate various structs/consts that are
equivalent to existing C interface for the syscall and
runtime package.
The cmd/cgo help message made that clear:
-godefs
for bootstrap: write Go definitions for C file to standard output
It's only intended to use when bootstrapping Go on
a new platform.
|
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. |
I may have taken what you posted here out of context, sorry. |
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: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?
The text was updated successfully, but these errors were encountered: