W1012 Constant expression violates subrange bounds

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

This message occurs if a conversion is made that was once legal but is now illegal, owing to the introduction of large unsigned types in Object Pascal after the Object Pascal 4 release.

For example:

    x: Integer;
    y = Cardinal(MaxInt) + 1;
    x := y;
    Writeln(y); // writes 2147483648
    Writeln(x); // writes -2147483648

Before Cardinal was defined as an unsigned 32-bit integer (prior to Object Pascal 4), Cardinal was an unsigned 31-bit integer with range 0..MaxInt. Thus, every value in the range of Cardinal would fit in an Integer. After Object Pascal 4, Cardinal has the full unsigned 32-bit range of 0..$FFFFFFFF. The top half of its range is not convertible to an Integer; very high values of Cardinal (greater than MaxInt) will thus be converted into negative Integer numbers, according to the differences in how signed (two's complement) and unsigned integers are interpreted.

See Also