https://www.freepascal.org/docs-html/rtl/system/default.html
Default is a compiler intrinsic: it returns for every type T 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.

But zero isn't always a valid value => so how can it be used to initialize a type where that is invalid.

The below will runtime error "invalid enum value".
(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).

So is that a bug in Default?
Or is the documentation wrong "any type"? (it contradicts itself anyway "zeroed" <> "any type")
Or ...?

program Project1;
type
  //tt = 3..5;
  tt = (e1=3, e2=5,e3=7);
var a: tt;
begin
  a := Default(tt);
  writeln(a);
  readln;
end.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to