[fpc-pascal] default value of a sub range field produces No range Check error

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Oct 16 12:11:06 CEST 2015

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 are not explicitly 
assigned, the instance is simply backed by a memory area that has been 
set to zero.

> Perhaps the compiler should have a warning when defining a sub-range
> field in class, telling users that it will be default to 0.

The documentation says this already: 
http://www.freepascal.org/docs-html/3.0.0/ref/refsu24.html ("The example 
demonstrates that values of fields are initialized with zero (or the 
equivalent of zero for non ordinal types: empty string, empty array and 
so on).") A warning would be overkill, I think.


More information about the fpc-pascal mailing list