c++11 enum syntax ok in DMD headers ?

S.G SG at somewhere.sg
Sat Nov 23 12:54:30 UTC 2019

On Friday, 22 November 2019 at 08:29:07 UTC, Iain Buclaw wrote:
> -------- Original Message --------
> On Nov 22, 2019, 8:55 AM, S.G via D.gnu < d.gnu at puremagic.com> 
> wrote:
> Hello, I've seen that many D enum are still typed as int because
> of the c++ headers but c++11 allow things like
> enum Stuff: unsigned char { ... }
> Is is ok to use this in the headers ?
> The baseline bootstrapping compiler is C++98.
> You don't have to type D enums as int, but the base type must 
> be used explicitly if you want to use them as parameters or 
> fields, which defeats some purposes of having the enum in the 
> first place.
> Work on autogenerating C++ headers should render this mostly 
> redundant (people want freedom to pick their std version), 
> apart from the not being able to use these enums as parameters 
> due to ABI/mangling incompatibilities.
> --
> Iain

Thanks for the quick replying, even if a bit disapointing.

The reason why I asked is because I'd like to avoid cases where 
the enum type is used directly and that creates an alignment 
issue that implies memory overhead, i.e

enum SomeEnumeratedType // could be `ubyte` or `unsigned char`
    member1, member2, member3

class Stuff
    ubyte[7] allTheOtherMembers; //let's say
    SomeEnumeratedType someEnumeratedType // now a Stuff instance 
takes 16 bytes
                                          // because 
SomeEnumeratedType takes 4 bytes...

More information about the D.gnu mailing list