Denis Koroskin wrote:
I'd put an assert and mad a case explicit, if there is a size_t is so
badly needed for ptr difference:
assert(p1 >= p2);
size_t y = cast(size_t)p1 - p2;
Aside from the typo in that code (!) the problem with casts is they are
a sledgehammer approach. Casts should be minimized because they *hide*
typing problems in the code. The more casts in the code, the more the
type-checking abilities of the compiler are disabled. I suspect this
will *hide* more bugs than it reveals.
The reality is is that most integers used in programs are positive and
relatively small. int and uint are equally correct for these, and people
tend to use both in a mish-mash. Trying to build a barrier between them
that requires explicit casting to overcome is going to require a lot of
casts that accomplish nothing other than satisfying a nagging, annoying
compiler.
I've used such a compiler - Pascal back in the early 80s. All the casts
it required me to insert basically sucked (and never revealed a single
bug). When I discovered C with its sensible system of implicit casting,
it was like putting on dry clothes after being soaked out in the cold rain.