extern(C) enum

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 15 07:24:34 UTC 2017


On Friday, September 15, 2017 04:15:57 bitwise via Digitalmars-d-learn 
wrote:
> I translated the headers for FreeType2 to D, and in many cases,
> enums are used as struct members.
>
> If I declare an extern(C) enum in D, is it guaranteed to have the
> same underlying type and size as it would for a C compiler on the
> same platform?

extern(C) should have no effect on enums. It's for function linkage, and
enums don't even have an address, so they don't actually end up in the
program as a symbol. And since C's int and D's int are the same on all
platforms that D supports (we'd have c_int otherwise, like we have c_long),
any enum with a base type of int (which is the default) will match what's in
C.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list