digitalmars.D.learn - D int and C/C++ int etc not really compatible when interfacing to
- Shriramana Sharma via Digitalmars-d-learn (13/13) Nov 01 2014 In the following pages:
- Kagamin (2/2) Nov 01 2014 D claims compatibility with system C compiler, which usually have
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (3/5) Nov 02 2014 ... and for C/C++ long which can be 32 or 64 bit, DMD recently
- Mike Parker (2/7) Nov 02 2014 Those aren't new. They have been in core.stdc.config for quite some time...
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (3/13) Nov 02 2014 Ah, I see. But DMD now has support for mangling these types
- ponce (4/14) Nov 02 2014 c_long and c_ulong get used, should c_int and c_uint too in
- Sean Kelly (5/8) Nov 02 2014 On common 32 and 64-bit platforms, the only type whose size
- Sean Kelly (4/9) Nov 02 2014 c_long and c_ulong have existed as aliases in core.stdc since the
- John Colvin (10/27) Nov 02 2014 Note this at the end of the "Data Type Compatiblity" section:
In the following pages: http://dlang.org/interfaceToC.html http://dlang.org/cpp_interface the "Data Type Compatibility" section says D int is compatible with C/C++ int. Isn't this actually false because D's integer types are fixed-size whereas C/C++'s are variable? So D int is only compatible with C++ int32_t, and who knows what that is typedef-ed to? Likewise for uint, long, short etc. So how to ensure, when calling C/C++, that the D int etc are being mapped to the correctly-sized C/C++ type? Does the compiler ensure that since the compatibility is being advertised as built-in? -- Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
Nov 01 2014
D claims compatibility with system C compiler, which usually have 32-bit int.
Nov 01 2014
On Saturday, 1 November 2014 at 21:00:54 UTC, Kagamin wrote:D claims compatibility with system C compiler, which usually have 32-bit int.... and for C/C++ long which can be 32 or 64 bit, DMD recently introduced the types c_long and c_ulong. (Not released yet.)
Nov 02 2014
On 11/2/2014 8:59 PM, "Marc Schütz" <schuetzm gmx.net>" wrote:On Saturday, 1 November 2014 at 21:00:54 UTC, Kagamin wrote:Those aren't new. They have been in core.stdc.config for quite some time.D claims compatibility with system C compiler, which usually have 32-bit int.... and for C/C++ long which can be 32 or 64 bit, DMD recently introduced the types c_long and c_ulong. (Not released yet.)
Nov 02 2014
On Sunday, 2 November 2014 at 12:37:13 UTC, Mike Parker wrote:On 11/2/2014 8:59 PM, "Marc Schütz" <schuetzm gmx.net>" wrote:Ah, I see. But DMD now has support for mangling these types correctly, in commit c4e0de64.On Saturday, 1 November 2014 at 21:00:54 UTC, Kagamin wrote:Those aren't new. They have been in core.stdc.config for quite some time.D claims compatibility with system C compiler, which usually have 32-bit int.... and for C/C++ long which can be 32 or 64 bit, DMD recently introduced the types c_long and c_ulong. (Not released yet.)
Nov 02 2014
On Sunday, 2 November 2014 at 12:37:13 UTC, Mike Parker wrote:On 11/2/2014 8:59 PM, "Marc Schütz" <schuetzm gmx.net>" wrote:c_long and c_ulong get used, should c_int and c_uint too in bindings? Looks like fringe use case.On Saturday, 1 November 2014 at 21:00:54 UTC, Kagamin wrote:Those aren't new. They have been in core.stdc.config for quite some time.D claims compatibility with system C compiler, which usually have 32-bit int.... and for C/C++ long which can be 32 or 64 bit, DMD recently introduced the types c_long and c_ulong. (Not released yet.)
Nov 02 2014
On Sunday, 2 November 2014 at 16:53:06 UTC, ponce wrote:c_long and c_ulong get used, should c_int and c_uint too in bindings? Looks like fringe use case.On common 32 and 64-bit platforms, the only type whose size changed between 32 and 64 bits is long, so the other aliases were deemed unnecessary. It's possible that as D is ported to more platforms this will have to change, but I seriously hope not.
Nov 02 2014
On Sunday, 2 November 2014 at 11:59:27 UTC, Marc Schütz wrote:On Saturday, 1 November 2014 at 21:00:54 UTC, Kagamin wrote:c_long and c_ulong have existed as aliases in core.stdc since the beginning. The change was to make them an explicit type so name mangling could be different.D claims compatibility with system C compiler, which usually have 32-bit int.... and for C/C++ long which can be 32 or 64 bit, DMD recently introduced the types c_long and c_ulong. (Not released yet.)
Nov 02 2014
On Saturday, 1 November 2014 at 15:00:57 UTC, Shriramana Sharma via Digitalmars-d-learn wrote:In the following pages: http://dlang.org/interfaceToC.html http://dlang.org/cpp_interface the "Data Type Compatibility" section says D int is compatible with C/C++ int. Isn't this actually false because D's integer types are fixed-size whereas C/C++'s are variable? So D int is only compatible with C++ int32_t, and who knows what that is typedef-ed to? Likewise for uint, long, short etc. So how to ensure, when calling C/C++, that the D int etc are being mapped to the correctly-sized C/C++ type? Does the compiler ensure that since the compatibility is being advertised as built-in?Note this at the end of the "Data Type Compatiblity" section: "These equivalents hold for most C compilers. The C standard does not pin down the sizes of the types, so some care is needed." D's built-in types do not change based on the companion C compiler. When linking to C, it is the programmers responsibility to ensure they are using the right types. core.stdc.config can help deal with the most common inconsistencies.
Nov 02 2014