primitive value overflow

bearophile bearophileHUGS at lycos.com
Thu May 23 16:58:15 PDT 2013


Peter Alexander:

> What about code that relies on overflow? It's well-defined 
> behaviour, so it should be expected that people rely on it (I 
> certainly do sometimes)

Do you rely on signed or unsigned overflow?

My opinions on this topic have changed few times.

A modern system language should offer the programmer both 
integral types for the rare situations where the overflow or wrap 
around are expected or acceptable, and other "default" integral 
types to be used in all the other situations, where overflow or 
wrap-around are unexpected and not desired. The implementation 
then should offer ways to optionally perform run-time tests on 
the second group of integrals.

A very good system language should also offer various means to 
statically verify the bounds of a certain percentage of values 
and expression results, to reduce the amount of run-time tests 
needed (here things like "Liquid Types" help).

D currently doesn't have such safe built-in types, and it doesn't 
offer means to create such efficient types in library code. I 
think such means should be provided:
http://d.puremagic.com/issues/show_bug.cgi?id=9850

Bye,
bearophile


More information about the Digitalmars-d mailing list