> the fact that it raises NO range check error during Create and the first
> writeln seems weird.
Line 16 (Inc statement) should raise one (ensure you're compiling with the
correct option, by default range checking is off), the others shouldn't.
Range check occurs on write, not read.
--
View
On 15/10/15 16:58, Dennis wrote:
>
> Perhaps the compiler should have a warning when defining a sub-range
> field in class, telling users that it will be default to 0.
>
Hi,
The problem is not restricted to classes.
Type
TSmall = 4..12;
Var B : TSmall;
...
Writeln (B):
Shows the same
Dennis wrote:
the fact that it raises NO range check error during Create and the first
writeln seems weird.
Range checks are inserted when a conversion from type A to type B
occurs, with A <> B (and then it checks whether the value is a valid
"type B" value). Values of fields in constructors
I tried with fpc 2.6.4
-
program Project1;
uses classes;
type
TSmall = 4..12;
TA=class
public
N : TSmall; //default to 0 after create, should raise range check error
end;
var
A : TA;
begin
A := TA.Create; //no range check error
writeln(A.N); //no range check error
in