On Sun, 2 Jul 2017, Tomas Hajny wrote:

By declaring it as a File of Enum, you are telling the compiler that it
contains only valid enums.

Noone can ever ensure, that a file doesn't get corrupted / tampered with
on a storage medium.

No-one can ensure a memory location cannot get corrupted either.

Moreover, using the same Read for reading from a text file _does_ perform
such checks (e.g. when using Read for reading an integer from a text file,
the value read is validated whether it conforms the given type and
potential failures are signalized either as an RTE, or a non-zero IOResult
depending on the $I state).

Text files by definition are not type safe. The compiler cannot know what it
contains.

By using file of enum (or any data type), you are explicitly telling the 
compiler it is OK.
The only exception is reference counted types; the compiler will forbid you
to define

myrecord = record
 a : ansistring;
 b : integer;
end;

f = file of myrecord;

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to