'int' is enough for 'length' to migrate code from x86 to x64
via Digitalmars-d
digitalmars-d at puremagic.com
Tue Nov 25 14:56:48 PST 2014
On Tuesday, 25 November 2014 at 18:24:29 UTC, Kagamin wrote:
> C++ legacy is huge especially in culture. That said, the true
> issue is in beliefs (which probably stem from 16-bit era).
> Can't judge Ada, have no experience with it, though examples of
> Java and .net show how marginal is importance of unsigned types.
Unsigned bytes are important, and I personally tend to make just
about everything unsigned when dealing with C-like languages
because that makes me aware of the pitfalls and I avoid the
signedness issue.
The downside is that it takes extra work to get the evaluation
order right and you have to take extra care to make sure loops
terminate correctly by being very conscious about +-1 issues when
terminating around zero.
But I don't really think C++ legacy is a good reason to keep
implicit coercion no matter what programming style one has.
Coercion is generally something I try to avoid, even explicitly,
so why would I want the compiler to do it with no warning?
> Such optimizations have a bad reputation. If they were more
> conservative and didn't propagate back in code flow, the
> situation would be probably better. Also isn't (x < x+1) a
> suspicious expression, is it a good idea to mess with it?
It is just an example, it could be the result of substituting
aliased values.
Anyway, I think it is important to not only define what happens
if you add 1 to 0xffffffff, but also define whether that result
is considered in correspondence with the type. If it isn't a
correct value for the type, then the programmer will have to make
no assumptions that optimizations will heed the resulting
incorrect value. The only acceptable alternative is to have the
language specification explicitly define the type as modular and
overflow free. If not you end up with weak typing…?
I personally would take the monotonic optimizations and rather
have a separate bit-fidling type that provides a clean builtin
swiss-army-knife toolset that gives close to direct access to the
whole arsenal that the CPU instruction set provides (carry,
ROL/ROR, bitcounts etc).
More information about the Digitalmars-d
mailing list