Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-09

conversion between types?

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bruce Bauman

I am porting a large body of code from the MetaWare Professional Pascal compiler to Free Pascal. The existing code makes extensive use of the MetaWare "retype" construct, which allows you to convert between types. For example:

retype(X, Rec1Ptr) will convert the obect X to the type "Rec1Ptr".

Is it possible to do something equivalent in FPC?

There are > 1000 uses of this, and I'd prefer to make the minimal modifications.

Thanks.

-- Bruce
CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Jonas Maebe
to Bruce Bauman
Bruce Bauman wrote 8 lines
I am porting a large body of code from the MetaWare Professional Pascal compiler to Free Pascal. The existing code makes extensive use of the MetaWare "retype" construct, which allows you to convert between types. For example: retype(X, Rec1Ptr) will convert the obect X to the type "Rec1Ptr". Is it possible to do something equivalent in FPC?

To what extent does it actually convert the data? If it's a simple type cast, you can use Rec1Ptr(X) instead (should be easy to change with a regular expression), albeit with one caveat: if you use this to convert from an integer type to a floating point type, then the compiler will perform an actual value conversion (i.e., it will not just reinterpret the bitpattern, except possibly in Delphi mode).

It would not be that hard to add support for this expression to the compiler though.

Jonas

Reply by email