Why is it that no one writes with portability in mind in druntime?
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Mon Nov 25 02:52:46 PST 2013
On 25/11/13 11:34, Jonathan M Davis wrote:
> Many people seem to just use int everywhere, and a lot of D code failed to
> compile when 64-bit support was finally added.
Ack :-(
One thing that slightly rings alarm bells for me with D is that, because the
integral sizes are fixed, people use short/ushort, int/uint, long/ulong etc. for
explicit 16-, 32- or 64-bit integrals. By contrast I do rather like the
explicitness of something like uint64_t as a means of saying, "Yes, at this
point in the code I really, really want a precisely 64-bit unsigned integral type."
IIRC we do have them in D code, but isn't their use frowned on?
>> The size_t case I rather like to think of is:
>>
>> size_t m = ...;
>> size_t p = 1 << m; // should this be 1U, 1UL ... ?
>
> I'd be _very_ suspicious of any bitshifts that aren't done on types with a
> fixed size.
This was in fact exactly how I learned about how to handle 32- vs 64-bit issues.
I had some simulation code suddenly start generating different values after I
installed a 64-bit OS.
My 32-bit code had run fine because the wraparound of the 1 << m bitshift
brought it back around to where it was supposed to be (I was shifting it by
about 30 or 31), whereas on 64-bit it was (surprise surprise) landing in the
wrong place.
I doubt that I can say that I've _never_ written unportable code since then, but
ever since, I've always tried to address such size-related issues.
More information about the Digitalmars-d
mailing list