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

cgo: doesn't handle #defines #435

Closed
rsc opened this issue Dec 16, 2009 · 3 comments
Closed

cgo: doesn't handle #defines #435

rsc opened this issue Dec 16, 2009 · 3 comments

Comments

@rsc
Copy link
Contributor

rsc commented Dec 16, 2009

cgo doesn't handle C.x where x is a #defined constant.
At least when x is a plain constant or a string, it would
be good to make C.x a valid Go const.
@rsc
Copy link
Contributor Author

rsc commented Dec 16, 2009

Comment 1:

The way to do this would be to parse the output of gcc -dM,
as the various scripts in src/pkg/syscall do.

Labels changed: added cgo.

@dhobsd
Copy link
Contributor

dhobsd commented Dec 30, 2009

Comment 2:

I have a patch to do this, but it's somewhat fragile for simplicity's sake. For
instance, if you use a #defined constant, say C.FOO, and FOO looks like
#define FOO some_func_call()
or something similar, it will translate into invalid Go code. I personally think this
is OK, because it doesn't make much sense to use defines in this way with the cgo
FFI. Additionally, it's quite a pain to try to parse C further to determine whether
it will, in fact, generate valid code.
Other than that, seems to work. Patch attached so I don't lose code; contains fixes
for two other cgo issues though, just waiting for Russ to get back so we can get
things committed cleanly.

Attachments:

  1. cgo.diff (5790 bytes)

@rsc
Copy link
Contributor Author

rsc commented Jan 11, 2010

Comment 3:

This issue was closed by revision bc82aad.

Status changed to Fixed.

Merged into issue #-.

@rsc rsc added fixed labels Jan 11, 2010
@rsc rsc self-assigned this Jan 11, 2010
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
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