[GSoC] Header Generation for C/C++

Manu turkeyman at gmail.com
Thu Jul 18 19:04:14 UTC 2019


On Wed, Jul 17, 2019 at 9:57 PM Iain Buclaw via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Wed, 17 Jul 2019 at 22:59, Manu via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
> >
> > On Wed, Jul 17, 2019 at 11:40 AM Eduard Staniloiu via Digitalmars-d
> > <digitalmars-d at puremagic.com> wrote:
> > >
> > > On Wednesday, 17 July 2019 at 17:41:23 UTC, Manu wrote:
> > > > On Wed, Jul 17, 2019 at 4:40 AM Eduard Staniloiu via
> > > > Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> > > >>
> > > >> enum TestEnum
> > > >> {
> > > >>      TESTENUMaa = 0,
> > > >>      TESTENUMbb = 1
> > > >> };
> > > >
> > > > What in earth is that?
> > >
> > > This is the convention that is used in the manually written
> > > headers in order to avoid name clashing between fields of
> > > different enums in the C headers
> >
> > Okay... but it's also the worst thing ever, and no real user would
> > want this code to be emit from the compiler ;)
> > Safe to say this is a strictly DMD-specific naming pattern, and I
> > don't think that should be our benchmark for a public-facing feature.
> >
> > A better non-C++11 name might be `TestEnum_aa`?
>
>
> I guess the most typical C/C++98 style would be:
>
> enum xml_status {
>   XML_STATUS_ERROR = 0,
>   XML_STATUS_OK = 1,
>   XML_STATUS_SUSPENDED = 2
> };
>
> Some may want the enum to be called xml_status_flags, or some may want
> a different prefix for the enum members.

Surely the keys should be created from string material that actually
exists? Applying random formatting to the strings feels pointless to
me. Just prefix the key with the enum name, and `_` is the
overwhelmingly established C identifier separator.
If you want your codebase to feel natural to C in the way you describe
above, then you can write:

enum XML_STATUS
{
  ERROR = 0,
  OK = 1,
  SUSPENDED = 2
}

D has a lot of meta that generates identifiers from things; if there's
arbitrary re-formatting rules in this tool, then they would end out
being mirrored around the place.


More information about the Digitalmars-d mailing list