digitalmars.D.learn - Best way to confine project to 64 bit builds only?
- NonNull (8/8) Oct 17 2020 I have inherited an open source C project that assumes that the
- Basile B. (12/20) Oct 17 2020 No it's wrong. A pointer always has the size of a general purpose
- NonNull (5/15) Oct 17 2020 You misunderstand. The original C only works if the size of a
- Adam D. Ruppe (2/4) Oct 17 2020 static assert(long.sizeof == void*.sizeof);
- NonNull (2/6) Oct 17 2020 That's a nice clean answer!
- Dennis (13/19) Oct 17 2020 If you want to exactly match the original C code's semantics, I
- NonNull (6/18) Oct 17 2020 That is useful information in general, I did not know about
I have inherited an open source C project that assumes that the size of a long and the size of a pointer are the same, and I have translated it into very similar D just like https://dlang.org/blog/2018/06/11/dasbetterc-converting-make-c-to-d/ D has the size of long fixed at 64 bits, so a pointer now has to be 64 bits. So I want to put something into the source to ensure an attempt to make a 32 bit build fails. What is the best way to do this?
Oct 17 2020
On Saturday, 17 October 2020 at 14:50:47 UTC, NonNull wrote:I have inherited an open source C project that assumes that the size of a long and the size of a pointer are the same, and I have translated it into very similar D just like https://dlang.org/blog/2018/06/11/dasbetterc-converting-make-c-to-d/ D has the size of long fixed at 64 bits, so a pointer now has to be 64 bits.No it's wrong. A pointer always has the size of a general purpose register.So I want to put something into the source to ensure an attempt to make a 32 bit build fails. What is the best way to do this?anyway you have several options: --- version(X86) static assert (false, "not for i386"); --- or --- static assert (size_t.sizeof != 4, "blablalala"); ---
Oct 17 2020
On Saturday, 17 October 2020 at 14:56:33 UTC, Basile B. wrote:On Saturday, 17 October 2020 at 14:50:47 UTC, NonNull wrote:You misunderstand. The original C only works if the size of a pointer is the same as the size of a long. So when translated into D in a simple way where the size of a long is always 64 bits the D will only work if the size of a pointer is 64 bits.I have inherited an open source C project that assumes that the size of a long and the size of a pointer are the same, and I have translated it into very similar D just like https://dlang.org/blog/2018/06/11/dasbetterc-converting-make-c-to-d/ D has the size of long fixed at 64 bits, so a pointer now has to be 64 bits.No it's wrong. A pointer always has the size of a general purpose register.
Oct 17 2020
On Saturday, 17 October 2020 at 14:50:47 UTC, NonNull wrote:I have inherited an open source C project that assumes that the size of a long and the size of a pointer are the samestatic assert(long.sizeof == void*.sizeof);
Oct 17 2020
On Saturday, 17 October 2020 at 14:56:35 UTC, Adam D. Ruppe wrote:On Saturday, 17 October 2020 at 14:50:47 UTC, NonNull wrote:That's a nice clean answer!I have inherited an open source C project that assumes that the size of a long and the size of a pointer are the samestatic assert(long.sizeof == void*.sizeof);
Oct 17 2020
On Saturday, 17 October 2020 at 14:50:47 UTC, NonNull wrote:I have inherited an open source C project that assumes that the size of a long and the size of a pointer are the same, and I have translated it into very similar D just like https://dlang.org/blog/2018/06/11/dasbetterc-converting-make-c-to-d/ D has the size of long fixed at 64 bits, so a pointer now has to be 64 bits.If you want to exactly match the original C code's semantics, I suggest translating (unsigned) long with c_long or c_ulong. You can import them here: ``` import core.stdc.config: c_long, c_ulong; ``` Then you could add this: ``` static assert(c_long.sizeof == size_t.sizeof); ``` This will fail on Windows 64 bit, where C longs are 32-bit and pointers 64-bit.
Oct 17 2020
On Saturday, 17 October 2020 at 15:03:29 UTC, Dennis wrote:If you want to exactly match the original C code's semantics, I suggest translating (unsigned) long with c_long or c_ulong. You can import them here: ``` import core.stdc.config: c_long, c_ulong; ``` Then you could add this: ``` static assert(c_long.sizeof == size_t.sizeof); ``` This will fail on Windows 64 bit, where C longs are 32-bit and pointers 64-bit.That is useful information in general, I did not know about core.stdc.config and it is useful in future projects! But for my project the C works at 64 bits except on Windows for the reason you gave. So by translating long in C to long in D it loses 32 bits but gains 64 bits on Windows. This is what I want.
Oct 17 2020