[fpc-pascal] Typecasting by accident
flavio.etrusco at gmail.com
Sat May 20 23:53:58 CEST 2006
I stand corrected. I've just checked Delphi5 and indeed it allows a
direct typecast from ansistring to any object/class :-/
But Delphi also allows direct cast from enumeration value to pointer
(which FPC doesn't allow), so maybe this is another nice oportunity to
be stricter than Delphi ;-)
On 5/15/06, Matt Emson <memsom at interalpha.co.uk> wrote:
> > No. Typecasts, as any other aspect of a language, has to have rules.
> > AFAIR this cast in Delphi would require another cast from AnsiString
> > to Pointer. And if typed pointers is enabled would require another
> > cast from Pointer to TObject.
> Nope. The C style cast is not type safe. Using the "as" operator is.
> p: pointer;
> i: integer;
> i := 10;
> p := TObject(i); //will work, but is invalid
> p := (i as TObject); //should fail (not tried) because i is not compatible
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
More information about the fpc-pascal