extern(C) enum

Mike Parker aldacron at gmail.com
Mon Sep 18 04:49:58 UTC 2017


On Monday, 18 September 2017 at 02:04:49 UTC, bitwise wrote:
> On Monday, 18 September 2017 at 00:12:49 UTC, Mike Parker wrote:
>> On Sunday, 17 September 2017 at 19:16:06 UTC, bitwise wrote:
>>> [...]
>>
>> I've been maintaining bindings to multiple C libraries 
>> (including Freetype 2 bindings) for 13 years now. I have never 
>> encountered an issue with an enum size mismatch. That's not to 
>> say I never will.
>
> For which platforms?
>
> I would have to actually go through the specs for each compiler 
> of each platform to make sure before I felt comfortable 
> accepting that int-sized enums were defacto standard.
>
> I would be worried about iOS, for example.
>
> The following code will run fine on Windows, but crash on iOS 
> due to the misaligned access:
>
> char data[8];
> int i = 0xFFFFFFFF;
> int* p = (int*)&data[1];
> *p++ = i;
> *p++ = i;
> *p++ = i;
>
> I remember this issue presenting due to a poorly written 
> serializer I used once (no idea who wrote it ;) and it makes me 
> wonder what kind of other subtle differences there may be.
>
> I think there may be a few (clang and gcc?) different choices 
> of compiler for Android NDK as well.

I know for certain that Derelict packages have been used on 
Windows, Linux, OS X, FreeBSD, and Android. I'm unsure about iOS. 
But I'm fairly confident that enums are int there just like they 
are everywhere else.




More information about the Digitalmars-d-learn mailing list