Prolog can “cast” one type of foreign term to another. This means that the foreign term is treated just as if it where the other type. This is done with the following procedure:
cast(+Foreign0, +New_type, -Foreign)
where Foreign is the foreign term that is the same data as Foreign0, only is of foreign type New_type. Foreign0 is not affected. This is much like casting in C.
Casting a foreign term to
address will get you the raw address of a
foreign term. This is not often necessary, but it is occasionally
useful in order to obtain an indexable value to use in the first
argument of a dynamic predicate you are maintaining. An
also be casted to a proper foreign type.
This predicate should be used with great care, as it is quite easy to get into trouble with this.