August 29, 2017 Re: C callbacks getting a value of 0! Bug in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johnson Jones | On Tuesday, 29 August 2017 at 01:34:40 UTC, Johnson Jones wrote:
> import core.stdc.config;
> pragma(msg, c_long.sizeof);
>
> prints 4UL
>
> both on x64 and x86
>
> and and C:
>
> void foo()
> {
> int dummy;
> switch (dummy) {
> case sizeof(long) :
> case sizeof(long) :
> break;
> }
> }
>
>
> produces 4 on both x86 and x64. So, I'm not sure how you are getting 8.
It's because you're on Windows. There, long/ulong are 4 bytes in both 32- and 64-bit. On Linux/Mac/*BSD, they're 4 in 32-bit and 8 in 64-bit. This is why we have c_long and c_ulong, to hide those differences.
|
August 29, 2017 Re: C callbacks getting a value of 0! Bug in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Moritz Maxeiner | On Tuesday, 29 August 2017 at 01:56:43 UTC, Moritz Maxeiner wrote: > On Tuesday, 29 August 2017 at 01:34:40 UTC, Johnson Jones wrote: >> [...] >> >> >> produces 4 on both x86 and x64. So, I'm not sure how you are getting 8. > > There are different 64bit data models [1] and it seems your platform uses LLP64, which uses 32bit longs. Am I correct in assuming you're on Windows (as they are the only major modern platform that I'm aware of that made this choice)? > > [1] https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models Yes. I found this, which gives a map for all the types: https://dlang.org/spec/interfaceToC.html Seems only long and ulong are issues. |
August 29, 2017 Re: C callbacks getting a value of 0! Bug in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johnson Jones | On Tuesday, 29 August 2017 at 02:47:34 UTC, Johnson Jones wrote:
> [...]
>
> Seems only long and ulong are issues.
With respect to the currently major platforms you can reasonable expect software to run on, yes.
Just don't try to use D on something with e.g. 32 bit C shorts unless you bind to it via c_short.
|
August 29, 2017 Re: C callbacks getting a value of 0! Bug in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johnson Jones | On 8/28/17 9:34 PM, Johnson Jones wrote:
> produces 4 on both x86 and x64. So, I'm not sure how you are getting 8.
Yes, this is exactly why you should use c_long and c_ulong, because just using int makes it not portable to other systems.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation