opImplicitCast/opImplicitCastFrom
Hxal
Hxal at freenode.irc
Mon Oct 27 09:10:42 PDT 2008
Simen Kjaeraas Wrote:
> So make all the normal built-in types (uint, int, float, etc) throw
> exceptions, and give access to lower-level types marked as unsafe.
> Basically, rename uint to 'uint_unsafe', and provide 'uint' as a typedef
> of Bounded!(uint_unsafe.min, uint_unsafe.max).
> I feel uint_unsafe is too long a name, but I'm sure something could be
> worked out (_uint?).
Both overflow-checked and wrap-around integers are useful, the latter kind
should not be viewed as inherently unsafe, but rather as a different set
of desired semantics. Ada calls these range types and modular types.
Efficient overflow checking would require the use of hardware exceptions,
which are currently not convertible to exceptions due to lack of compiler
support for non-call exceptions (on Linux at least).
But anyway, the point was to include the implicit cast mechanism to allow
the user to implement such interesting things. No point putting ranged types
into the language if it can be made perfectly doable at library level.
If you put them in the standard lib, people who care about security will
surely use them. (At least if you don't call the type Bounded :P)
More information about the Digitalmars-d
mailing list