-
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: #define is not exportable in some situations #18720
Comments
We currently only support very simple macros that simply renames a value.
The reason is that to support complicated macros like *&var or even
HELLO_WORLD, cgo must implement its own C parser and translate the C
expression into equivalent Go.
Right now, only VAR1 and HELLO work and "#define PI 3" also works, and I
think we can make "#define PI 3.14" and possibly VAR work too, but I don't
think we can make the others work. They might appear simple, but supporting
them still requires a full C parser.
The workaround is to assign the macro into a C variable or const and then
use them in Go.
[Updated to correct the false statement that cgo currently supports VAR
as it only supports VAR1.]
|
Thank you for quick reply! I think we can solve testVariablePropagation also. x.h
x.txt
output:
So, we can get a finalized definition, instead of a shallow definition. Line 267 in ea7d9e6
|
CL https://golang.org/cl/35511 mentions this issue. |
For @ianlancetaylor to decide/review. |
Current code doesn't support floating point #define macros. This CL compiles floats to a object file and retrive values from it. That approach is the same work as we've already done for integers. Updates #18720 Change-Id: I88b7ab174d0f73bda975cf90c5aeb797961fe034 Reviewed-on: https://go-review.googlesource.com/35511 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
CL https://golang.org/cl/41312 mentions this issue. |
CL https://golang.org/cl/41910 mentions this issue. |
CL https://golang.org/cl/43970 mentions this issue. |
Current code cannot handle string #define macros if those macros are defined via other macros. This CL solve the issue. Updates #18720 Change-Id: Ibed0773d10db3d545bb246b97e81c0d19e3af3d5 Reviewed-on: https://go-review.googlesource.com/41312 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
No CL for this and we're deep in the freeze, moving to go1.10. |
I didn't complete that because it conflicts with https://go-review.googlesource.com/c/44290/ |
Change https://golang.org/cl/86475 mentions this issue: |
https://golang.org/cl/43970 changed writeOutputFunc to support niladic function-like macros; apply the corresponding change to writeGccgoOutputFunc. Updates #10715 Updates #18720 Change-Id: I5decb1d37ec71507466ade2eeda4b89c8785eaef Reviewed-on: https://go-review.googlesource.com/86475 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Hiroshi Ioka <hirochachacha@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Please answer these questions before submitting your issue. Thanks!
What did you do?
I know 4 failing scenarios.
What did you expect to see?
no errors.
What did you see instead?
none of them can compile.
Does this issue reproduce with the latest release (go1.7.4)?
I think so.
System details
The text was updated successfully, but these errors were encountered: