[fpc-devel] conversion between types?

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Sep 15 14:45:23 CEST 2009


On 15 Sep 2009, at 14:37, Bruce Bauman wrote:

> 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



More information about the fpc-devel mailing list