-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: const initializer C: extern const
is not a constant
#51044
Comments
If I change But in fact, I was mapping c++ enum to golang, I can't use namespace in the header file |
Afaik, CGO does not support C++. You will have to make a pure C wrapper first |
Yes, I'm making c wrapper, but how can I warp c++ enum to c (constantly)? |
An extern int in C is much like a global variable, so I think that is why it maps to a variable in Go. The concept of a const in Go, where they are compile time constants), and in C(++) where const are in fact run time immutable variable, is fundamentally different. The one cannot always be mapped to the other. |
A C |
I cannot understand why And it cannot work, if I use var (
CONST_VAR int = (int)(C.CONST_VAR)
) It will work. but how about want to use |
Go does not have the concept of an "external constant." In Go, all constant values are known at the point where the constant is declared. When the cgo tool see a C |
Oh, now I see that I misunderstood the example. The code const (
CONST_VAR int = (int)(C.CONST_VAR)
) can't work in Go for a C |
Ok, I think I can understand now, but It's hard to change my habit, I'll close it now |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
consttest.go
consttest.h
consttest.cpp
consttest_test.go
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: