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

Don't name anonymous enums #29

Closed
joakim-noah opened this issue Aug 14, 2014 · 10 comments
Closed

Don't name anonymous enums #29

joakim-noah opened this issue Aug 14, 2014 · 10 comments

Comments

@joakim-noah
Copy link

D allows them, so I had to search-and-replace to get the Anonymous_x names out.

@jacob-carlborg
Copy link
Owner

Do you have an example of C code causing this problem?

@joakim-noah
Copy link
Author

Try any anonymous enum with multiple elements. For example, the following is taken from a header I was translating:

enum {
ASENSOR_TYPE_ACCELEROMETER      = 1,
ASENSOR_TYPE_MAGNETIC_FIELD     = 2,
ASENSOR_TYPE_GYROSCOPE          = 4,
ASENSOR_TYPE_LIGHT              = 5,
ASENSOR_TYPE_PROXIMITY          = 8
};

It got translated to this:

extern (C):
enum _Anonymous_0
{
    ASENSOR_TYPE_ACCELEROMETER = 1,
    ASENSOR_TYPE_MAGNETIC_FIELD = 2,
    ASENSOR_TYPE_GYROSCOPE = 4,
    ASENSOR_TYPE_LIGHT = 5,
    ASENSOR_TYPE_PROXIMITY = 8
}

Nobody's going to want to write _Anonymous_0.ASENSOR_TYPE_ACCEROMETER all over their code.

@jacob-carlborg
Copy link
Owner

I'll see what I can do about it.

@jacob-carlborg jacob-carlborg mentioned this issue Jun 21, 2016
@ciechowoj
Copy link
Contributor

There is some problem with translating a corner case. Consider following code:

enum {
    FOO,
    BAR,
} baz;

D doesn't allow such a construction, so the enum is required to have explicit name, on the other side the enum items are still visible in global space. The best thing I can think of at the moment is to declare baz as int.

@ciechowoj
Copy link
Contributor

The best solution would be to name the enum and still export its items to the global scope.

@jacob-carlborg
Copy link
Owner

Yeah, just through an alias.

@ciechowoj
Copy link
Contributor

Could you provide an example ?

@ciechowoj
Copy link
Contributor

Do you mean to repeat all the enumeration items as the aliases in global scope?

@jacob-carlborg
Copy link
Owner

enum  _Anonymous_0
{
    FOO,
    BAR
}

alias FOO = _Anonymous_0.FOO;
alias BAR = _Anonymous_0.BAR;

@ciechowoj
Copy link
Contributor

Well, this can be done.

ciechowoj added a commit to ciechowoj/dstep that referenced this issue Jun 25, 2016
Fix comments containing format specifiers.
ciechowoj added a commit to ciechowoj/dstep that referenced this issue Jun 25, 2016
Fix comments containing format specifiers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants