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: C typedef not reflect in Go #12599

Closed
meihuabo opened this issue Sep 12, 2015 · 4 comments
Closed

cmd/cgo: C typedef not reflect in Go #12599

meihuabo opened this issue Sep 12, 2015 · 4 comments
Milestone

Comments

@meihuabo
Copy link

source code:

package main
import (
    "fmt"
    "reflect"
)
/*
#define ARCH_BAD ~0
typedef unsigned int uint32_t;
const uint32_t C_ARCH_BAD = ARCH_BAD;
*/
import "C"
func main() {
    fmt.Println(reflect.TypeOf(C.C_ARCH_BAD))
}

and the result is :

main._Ctype_uint

not the result I expect:

main._Ctype_uint32_t

I use the cgo tool and here is a part of the results:

var _Cvar_C_ARCH_BAD *_Ctype_uint = (*_Ctype_uint)(unsafe.Pointer(&__cgo_C_ARCH_BAD))

Here is some info about my server

------------------------go version-----------------------------------
root@meihuabo:~# go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/local/go"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

root@meihuabo:~# go version
go version go1.5.1 linux/amd64

---------------------server info--------------------------------------

root@meihuabo:~# uname -a
Linux meihuabo 3.8.0-44-generic #66~precise1-Ubuntu SMP Tue Jul 15 04:01:04 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

root@meihuabo:~# cat /proc/version
Linux version 3.8.0-44-generic (buildd@tipua) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #66~precise1-Ubuntu SMP Tue Jul 15 04:01:04 UTC 2014

root@meihuabo:~# cat /etc/issue
Ubuntu 12.04.5 LTS \n \l

root@meihuabo:~# cat /proc/cpuinfo 
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz
stepping    : 7
microcode   : 0x70d
cpu MHz     : 2300.062
cache size  : 15360 KB
physical id : 0
siblings    : 1
core id     : 0
cpu cores   : 1
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl pni ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm
bogomips    : 4600.12
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:
@ianlancetaylor ianlancetaylor changed the title a problem about run c code in go cmd/cgo: a problem about run c code in go Sep 12, 2015
@ianlancetaylor
Copy link
Contributor

When I run your program using GCC 4.8.4 on Ubuntu Trusty it prints
main._Ctype_uint32_t

In general cgo determines the C type from the debug info generated by the C compiler. What compiler are you using?

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Sep 12, 2015
@ianlancetaylor ianlancetaylor changed the title cmd/cgo: a problem about run c code in go cmd/cgo: C typedef not reflect in Go Sep 12, 2015
@meihuabo
Copy link
Author

root@meihuabo:~# gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

@ianlancetaylor
Copy link
Contributor

I can verify that when I use GCC 4.6 I get main._Ctype_uint. Since it seems to work with newer versions of GCC, I don't think there is anything for us to fix. Please feel to reopen if you disagree, but you'll have to identify the fix yourself.

@meihuabo
Copy link
Author

thank you very much!
I have upgrade my gcc to gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)
and it worked:

main._Ctype_uint32_t

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants