Why is it that no one writes with portability in mind in druntime?
Jonathan M Davis
jmdavisProg at gmx.com
Mon Nov 25 03:51:07 PST 2013
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