Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-02 Thread via Digitalmars-d-learn

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.)


Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-02 Thread John Colvin via Digitalmars-d-learn
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.


Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-02 Thread Mike Parker via Digitalmars-d-learn

On 11/2/2014 8:59 PM, Marc Schütz schue...@gmx.net wrote:

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.)


Those aren't new. They have been in core.stdc.config for quite some time.


Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-02 Thread via Digitalmars-d-learn

On Sunday, 2 November 2014 at 12:37:13 UTC, Mike Parker wrote:

On 11/2/2014 8:59 PM, Marc Schütz schue...@gmx.net wrote:

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.)


Those aren't new. They have been in core.stdc.config for quite 
some time.


Ah, I see. But DMD now has support for mangling these types 
correctly, in commit c4e0de64.


Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-02 Thread Sean Kelly via Digitalmars-d-learn

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:
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.)


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.


Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-02 Thread ponce via Digitalmars-d-learn

On Sunday, 2 November 2014 at 12:37:13 UTC, Mike Parker wrote:

On 11/2/2014 8:59 PM, Marc Schütz schue...@gmx.net wrote:

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.)


Those aren't new. They have been in core.stdc.config for quite 
some time.


c_long and c_ulong get used, should c_int and c_uint too in 
bindings?

Looks like fringe use case.


Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-02 Thread Sean Kelly via Digitalmars-d-learn

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.


D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-01 Thread Shriramana Sharma via Digitalmars-d-learn
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 ஶ்ரீரமணஶர்மா श्रीरमणशर्मा



Re: D int and C/C++ int etc not really compatible when interfacing to C/C++

2014-11-01 Thread Kagamin via Digitalmars-d-learn
D claims compatibility with system C compiler, which usually have 
32-bit int.