Skip to content

cmd/cgo: doesn't properly recognize a typedef'd C array type when it's a const C function argument #7270

Open
@gopherbot

Description

@gopherbot

by krzysiek@dajerade.pl:

I ran into an issue with cgo, when integrating Go with some C code. The attached tarball
contains a minimal example that reproduces the problem. Basicaly, passing a variable of
a typedef'd array type to a function accepting a const argument results in a "type
mismatch" compilation error.

C:

typedef unsigned char Bar[12];

void foo(Bar* f); // this works
void foo2(const Bar* f); // this confuses cgo

Go:

func main() {
  var v C.Bar
  C.foo(&bar) // this works
  C.foo2(&bar) // error, pasted below
}

This doesn't happen on Mac OS, go version go1.2 darwin/amd64, I don't know about Windows
builds.

What steps will reproduce the problem?
1. tar zxf const-bug.tar.gz && cd const-bug && make

What is the expected output?
Program should compile.

What do you see instead?
src/kg/constbug/main.go:12: cannot use &bar (type *_Ctype_Bar) as type
*[12]_Ctype_unsignedchar in function argument

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Ubuntu 12.04

Which version are you using?  (run 'go version')
go version go1.2 linux/amd64
Installed from https://go.googlecode.com/files/go1.2.linux-amd64.tar.gz

Attachments:

  1. const-bug.tar.gz (1144 bytes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestedIssues that may be good for new contributors looking for work to do.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions