'int' is enough for 'length' to migrate code from x86 to x64

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 20 07:52:22 PST 2014


On Thu, Nov 20, 2014 at 12:02:42AM -0800, Walter Bright via Digitalmars-d wrote:
> On 11/19/2014 5:03 PM, H. S. Teoh via Digitalmars-d wrote:
> >If this kind of unsafe mixing wasn't allowed, or required explict
> >casts (to signify "yes I know what I'm doing and I'm prepared to face
> >the consequences"), I suspect that bearophile would be much happier
> >about this issue. ;-)
> 
> Explicit casts are worse than the problem - they can easily cause
> bugs.

Not any worse bugs than are currently *silently accepted* by the
compiler!


> As for me personally, I like having a complete set of signed and
> unsigned integral types at my disposal. It's like having a full set of
> wrenches that are open end on one end and boxed on the other :-) Most
> of the time either end will work, but sometimes only one will.
> 
> Now, if D were a non-systems language like Basic, Go or Java, unsigned
> types could be reasonably dispensed with. But D is a systems
> programming language, and it ought to have available types that match
> what the hardware supports.

Please note that I never suggested anywhere that we get rid of unsigned
types. In fact, I think it was a right decision to include unsigned
types in the language and to use an unsigned type for array length.

What *could* be improved, is the prevention of obvious mistakes in
*mixing* signed and unsigned types. Right now, D allows code like the
following with no warning:

	uint x;
	int y;
	auto z = x - y;

BTW, this one is the same in essence as an actual bug that I fixed in
druntime earlier this year, so downplaying it as a mistake people make
'cos they confound computer math with math math is fallacious.


T

-- 
He who laughs last thinks slowest.


More information about the Digitalmars-d mailing list