Giter Site home page Giter Site logo

Comments (10)

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024 1

I'll see what I can do about it.

from dstep.

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024

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

from dstep.

joakim-noah avatar joakim-noah commented on July 2, 2024

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.

from dstep.

ciechowoj avatar ciechowoj commented on July 2, 2024

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.

from dstep.

ciechowoj avatar ciechowoj commented on July 2, 2024

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

from dstep.

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024

Yeah, just through an alias.

from dstep.

ciechowoj avatar ciechowoj commented on July 2, 2024

Could you provide an example ?

from dstep.

ciechowoj avatar ciechowoj commented on July 2, 2024

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

from dstep.

jacob-carlborg avatar jacob-carlborg commented on July 2, 2024
enum  _Anonymous_0
{
    FOO,
    BAR
}

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

from dstep.

ciechowoj avatar ciechowoj commented on July 2, 2024

Well, this can be done.

from dstep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.