<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<a class="moz-txt-link-freetext" href="https://www.freepascal.org/docs-html/rtl/system/default.html">https://www.freepascal.org/docs-html/rtl/system/default.html</a><br>
<blockquote type="cite"><var>Default</var> is a compiler intrinsic:
it returns for every type <var>T</var> a default value. In
essence, this is a block of memory that is zeroed out. It can be
used to correctly initialize any type, and more importantly, a
managed type. It also works using a generic type template. </blockquote>
<br>
But zero isn't always a valid value => so how can it be used to
initialize a type where that is invalid.<br>
<br>
The below will runtime error "invalid enum value".<br>
(And also, in the past, I saw it pointed out countless times, that
setting an enum to an ordinal value that is not matching any of its
members does not have a defined behaviour).<br>
<br>
So is that a bug in Default? <br>
Or is the documentation wrong "any type"? (it contradicts itself
anyway "zeroed" <> "any type") <br>
Or ...?<br>
<br>
program Project1;<br>
type <br>
//tt = 3..5;<br>
tt = (e1=3, e2=5,e3=7);<br>
var a: tt;<br>
begin<br>
a := Default(tt);<br>
writeln(a);<br>
readln;<br>
end.<br>
<br>
</body>
</html>