Why is it that no one writes with portability in mind in druntime?

froglegs nono at yahoo.com
Tue Nov 26 00:10:12 PST 2013


  I understand that it is converting a uint32 to a int32.  My 
point is that in C++ you can make this a warning, and then make 
all warnings errors. So this would not compile in any sane 
codebase since a int cannot express the full range of a uint. 
Perhaps D just better errors/warnings if it is unable to capture 
this...


On Monday, 25 November 2013 at 11:51:22 UTC, Jonathan M Davis 
wrote:
> On Monday, November 25, 2013 12:14:59 froglegs wrote:
>> >>int len = arr.length;
>> 
>>   That isn't an error in D?
>> 
>>   Every C++ code base I've worked in enables max 
>> warnings/warnings
>> as errors, this would never compile--
>> 
>>   Does it at least trigger a warning?
>
> No. It's not a warning, and dmd is not big on warnings (and 
> IMHO warnings you
> should be abolished, but that's another discussion). 
> Regardless, given how
> size_t is implemented, the compiler doesn't really even know 
> that it exists
> anyway. It's aliased to uint on 32-bit systems and ulong on 
> 64-bit systems, so
> every place that size_t is used, it gets replaced with the type 
> that it's
> aliased to, and the compiler forgets that it was ever anything 
> else - the same
> thing happens with all aliases.
>
> So, on 32-bit systems, size_t is uint and
>
> int len = arr.length;
>
> works just fine, because uint implicitly converts to int. 
> Whereas on 64-bit
> systems, size_t is ulong, and ulong does _not_ implicitly 
> convert to int, so
> you get an error.
>
> So, on 32-bit systems, it compiles just fine, and 64-bit 
> systems you get an
> error, but no systems will give you a warning.
>
> - Jonathan M Davis



More information about the Digitalmars-d mailing list