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.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
This code:
#ifdef __cplusplus
class Test1 {};
class Test2 {};
class Test3 {};
#else
typedef struct Test1 Test1;
typedef void Test2;
typedef int Test3;
#endif
Should generate Go types and use them in functions.
What is the expected output?
_cgo_gotypes.go:
// ...
type _Ctype_void [0]byte
type _Ctype_int int32
type _Ctype_Test1 _Ctype_void
type _Ctype_Test2 _Ctype_void
type _Ctype_Test3 _Ctype_int
func _Cfunc_TestFunc1(*_Ctype_Test1) _Ctype_void
func _Cfunc_TestFunc2(*_Ctype_Test2) _Ctype_void
func _Cfunc_TestFunc3(*_Ctype_Test3) _Ctype_void
What do you see instead?
_cgo_gotypes.go:
// ...
type _Ctype_Test2 _Ctype_void
type _Ctype_Test3 _Ctype_int
type _Ctype_int int32
type _Ctype_void [0]byte
func _Cfunc_TestFunc1(*[0]byte) _Ctype_void
func _Cfunc_TestFunc2(unsafe.Pointer) _Ctype_void
func _Cfunc_TestFunc3(*_Ctype_Test3) _Ctype_void
Which compiler are you using (5g, 6g, 8g, gccgo)?
gc default
g++ 4.8 (GNU) OR clang++
Which operating system are you using?
OS X 10.8.5
Which version are you using? (run 'go version')
go version devel +f4d1cb8d9a91 Thu Sep 19 22:34:33 2013 +1000 darwin/amd64
Please provide any additional information below.
Run it like this:
CXX=g++-4.8 go tool cgo -- cgotest.go
CXX=clang++ go tool cgo -- cgotest.go
Test case attached.
For Test3, sure I am. And it works. Test2 isn't a unique type, it's just an alias of
void (another typedef of void would be considered the same type in C).
Test1 is a unique and honest type. It declares "something" that can be passed around as
a pointer, but not understandable by C.
These two types are considered different in C:
typedef struct Foo Foo;
typedef struct Bar Bar;
Yet Go translates both explicitly to [0]byte. The two should be separately translated to
_Ctype_Foo _Ctype_Bar.
Strangely in my example Test2 is given a type, but that type is not used. Test1 is a
legitiment type, yet none is generated or used.
I guess to make this work I will have to continue lying to cgo. Although I don't
consider "typedef struct Test1 Test1;" a lie at all.
Attachments:
The text was updated successfully, but these errors were encountered: