[fpc-pascal] Case in Record
"Vinzent Höfler"
JeLlyFish.software at gmx.net
Thu Oct 8 21:50:59 CEST 2009
"Jürgen Hestermann" <juergen.hestermann at gmx.de>:
> >> And I don't know any other Pascal Compiler who does any checks in
> >> this direction. Do some?
> > I don't know, but ADA reportedly does.
Yes, but the semantics of discriminants is slightly different than in PASCAL.
> I don't know the differences to Pascal. Does it have the same syntax for
> variant records?
No.
> Of course it would be. But how should it work? Setting the tag variable
> when assigning a value and raising an error when reading with different
> variant? Then what if the tag variable is changed directly? Or should it
> be readonly (which would make sense IMHO).
Well, variant records with read-only discriminants don't make much sense IME. They are just too inflexible.
In Ada both variants (discriminant is constant or changeable) are supported. To change the discriminant of such a (unconstrained) variable a whole-record assignment is needed, constrained variables (discriminant is initialized at declaration time) can't change their discriminant anymore. So validity checks can be done on both read and (partial) write accesses.
With the current state of FPC, discriminant-checked records with changeable discriminants would be possible without changing rules or syntax. If you want them read-only the rules must probably change. ;)
Vinzent.
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
More information about the fpc-pascal
mailing list