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: pointers of Objective-C classes compatibility #7039

hajimehoshi opened this Issue Dec 31, 2013 · 2 comments


None yet
4 participants
Copy link

hajimehoshi commented Dec 31, 2013

What steps will reproduce the problem?
If possible, include a link to a program on

A pointer of an Objective-C class can't be assigned to a variable as a pointer of
another Objective-C class. For example:

package main

// #cgo CFLAGS: -x objective-c                                                          
// @class Foo;                                                                          
// @class Bar;                                                                          
import "C"

func main() {
        var foo *C.Foo
        var bar *C.Bar

        foo = bar // ?                                                                                                                                                                                                                                                          


What is the expected output?
Compile Error

What do you see instead?
Compile succeeded
("0x00x0" was printed)

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

Which operating system are you using?
Mac OS X 10.9

Which version are you using?  (run 'go version')
go version go1.2 darwin/amd64

Please provide any additional information below.

This comment has been minimized.

Copy link

ianlancetaylor commented Dec 31, 2013

Comment 1:

For the record, both foo and bar are given the Go type "*[0]byte", and as such one can
be assigned to the other.

Labels changed: added release-none, repo-main.

Status changed to Accepted.


This comment has been minimized.

Copy link

mdempsky commented Aug 14, 2014

Comment 2:

For what it's worth, Go 1.3 on linux/amd64 using either CC=gcc or CC=clang, C.Foo and
C.Bar are now rewritten as _Ctype_struct_Foo and _Ctype_struct_Bar, which are both
defined as "struct{}".  So the Go compiler now rejects the "foo = bar" assignment
because "*_Ctype_struct_Foo" and "*_Ctype_struct_Bar" are distinct types.
Thus I think the "expected output" from the issue report is now satisfied, though it
might be worthwhile if someone could verify on OS X too.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed release-none labels Apr 10, 2015

@dmitshur dmitshur changed the title cmd/cgo: pointers of Objective-C classes compativility cmd/cgo: pointers of Objective-C classes compatibility Oct 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.