Re: extern(C) enum

2017-09-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Monday, 18 September 2017 at 02:04:49 UTC, bitwise wrote: The following code will run fine on Windows, but crash on iOS due to the misaligned access: Interesting, does iOS crash such a process intentionally, or is it a side effect? char data[8]; int i = 0x; int* p = (int*)&dat

Re: extern(C) enum

2017-09-17 Thread Mike Parker via Digitalmars-d-learn
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

Re: extern(C) enum

2017-09-17 Thread bitwise via Digitalmars-d-learn
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 mis

Re: extern(C) enum

2017-09-17 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 17 September 2017 at 19:16:06 UTC, bitwise wrote: On Sunday, 17 September 2017 at 18:44:47 UTC, nkm1 wrote: On Sunday, 17 September 2017 at 17:06:10 UTC, bitwise wrote: [...] Just put the burden on the users then. It's implementation defined, so they are in position to figure it o

Re: extern(C) enum

2017-09-17 Thread bitwise via Digitalmars-d-learn
On Sunday, 17 September 2017 at 18:44:47 UTC, nkm1 wrote: On Sunday, 17 September 2017 at 17:06:10 UTC, bitwise wrote: [...] Just put the burden on the users then. It's implementation defined, so they are in position to figure it out... This isn't something that can really be done with bind

Re: extern(C) enum

2017-09-17 Thread nkm1 via Digitalmars-d-learn
On Sunday, 17 September 2017 at 17:06:10 UTC, bitwise wrote: I don't really see a way to deal with this aside from branching the entire library and inserting something like 'FT_SIZE_REQUEST_TYPE__FORCE_INT = 0x' into every enum incase the devs used it in a struct. Just put the burden

Re: extern(C) enum

2017-09-17 Thread bitwise via Digitalmars-d-learn
On Saturday, 16 September 2017 at 12:34:58 UTC, nkm1 wrote: On Saturday, 16 September 2017 at 03:06:24 UTC, Timothy Foster wrote: [...] [...] So it appears I'm screwed then. Example: typedef enum FT_Size_Request_Type_ { FT_SIZE_REQUEST_TYPE_NOMINAL, FT_SIZE_REQUEST_TYPE_REAL_DIM,

Re: extern(C) enum

2017-09-16 Thread nkm1 via Digitalmars-d-learn
On Saturday, 16 September 2017 at 03:06:24 UTC, Timothy Foster wrote: You are correct, however 6.7.2.2 "Enumeration specifiers" states: "Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shal

Re: extern(C) enum

2017-09-15 Thread Timothy Foster via Digitalmars-d-learn
On Friday, 15 September 2017 at 19:35:50 UTC, nkm1 wrote: On Friday, 15 September 2017 at 19:21:02 UTC, Timothy Foster wrote: I believe C enum size is implementation defined. A C compiler can pick the underlying type (1, 2, or 4 bytes, signed or unsigned) that fits the values in the enum. No,

Re: extern(C) enum

2017-09-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 15, 2017 19:04:56 jmh530 via Digitalmars-d-learn wrote: > On Friday, 15 September 2017 at 18:20:06 UTC, Jonathan M Davis > > wrote: > > It is my understanding that for both C and C++, an enum is > > always an int (unless you're talking about enum classes in > > C++). The size o

Re: extern(C) enum

2017-09-15 Thread bitwise via Digitalmars-d-learn
On Friday, 15 September 2017 at 19:35:50 UTC, nkm1 wrote: On Friday, 15 September 2017 at 19:21:02 UTC, Timothy Foster wrote: I believe C enum size is implementation defined. A C compiler can pick the underlying type (1, 2, or 4 bytes, signed or unsigned) that fits the values in the enum. No,

Re: extern(C) enum

2017-09-15 Thread nkm1 via Digitalmars-d-learn
On Friday, 15 September 2017 at 19:21:02 UTC, Timothy Foster wrote: I believe C enum size is implementation defined. A C compiler can pick the underlying type (1, 2, or 4 bytes, signed or unsigned) that fits the values in the enum. No, at least, not C99. See 6.4.4.3: "An identifier declared as

Re: extern(C) enum

2017-09-15 Thread Timothy Foster via Digitalmars-d-learn
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&#

Re: extern(C) enum

2017-09-15 Thread jmh530 via Digitalmars-d-learn
On Friday, 15 September 2017 at 18:20:06 UTC, Jonathan M Davis wrote: It is my understanding that for both C and C++, an enum is always an int (unless you're talking about enum classes in C++). The size of an int can change based on your architecture, but AFAIK, all of the architectures suppo

Re: extern(C) enum

2017-09-15 Thread Jonathan M Davis via Digitalmars-d-learn
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 s

Re: extern(C) enum

2017-09-15 Thread bitwise via Digitalmars-d-learn
On Friday, 15 September 2017 at 07:24:34 UTC, Jonathan M Davis wrote: 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

Re: extern(C) enum

2017-09-15 Thread bitwise via Digitalmars-d-learn
On Friday, 15 September 2017 at 06:57:31 UTC, rikki cattermole wrote: On 15/09/2017 5:15 AM, bitwise 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

Re: extern(C) enum

2017-09-15 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: extern(C) enum

2017-09-15 Thread rikki cattermole via Digitalmars-d-learn
On 15/09/2017 5:15 AM, bitwise 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? No need

extern(C) enum

2017-09-14 Thread bitwise via Digitalmars-d-learn
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?