BufferedFile bug?

Janice Caron caron800 at googlemail.com
Fri Mar 7 01:15:09 PST 2008


On 07/03/2008, Lionello Lunesu <lionello at lunesu.remove.com> wrote:
> Found it:
>
>  http://erdani.org/d-implicit-conversions.pdf

I tried downloading that (unsuccessfully). However, it seems to me
that we don't need a diagram. The rule can be easily expressed purely
in logic.

It is safe to implicitly convert from type T to type U, if and only if
both of the following two rules apply:

(1) There exists no value x of type T for which
    cast(T) cast(U) x != x

(2) There exists no value x of type T, and no type V, for which
    cast(V) x != cast(V) cast(U) x

Finding a single counterexample to either of those rules is sufficient
to prove a conversion unsafe. For example, one cannot safely
implicitly cast an int to a short, because rule (1) is violated (e.g.
with counterexample x == 0x10000). Likewise, one cannot safely
implicitly cast a uint to an int, because rule (2) is violated (e.g.
with counterexample x == 0xFFFFFFFF and V == long)

Well, that blows C integer promotion rules out of the window! :-)



More information about the Digitalmars-d mailing list