Page 1 of 1

Posted: 27 Jan 2015 13:46
by Martin Meyer
The Language Reference says about uncheckedConvert: >>It makes only compile time checking of bit-size equality of the converted domains.<< But why below predicate test outputs in 64 bit mode (in 7501) "converted variable of size 4 unchecked to variable of size 8"? Its further output "IntNative = -2147483648" shows, that it did not convert a memory address (of an unsigned) unchecked to an unsignedNative, but that in fact the value of the variable Var has been converted.

Code: Select all

class predicates     test : (). clauses     test() :-         hasDomain(integer, LowInt),         LowInt = lowerBound(integer),         stdIo::write("lowerBound(integer) = ", LowInt, "\n"),         test_1(LowInt).   class predicates     test_1 : (Type Var). clauses     test_1(Var) :-         IntNative = uncheckedConvert(integerNative, Var),         stdIo::write("converted variable of size ", sizeOf(Var), " unchecked to variable of size ", sizeOf(IntNative), "\n"),         stdIo::write("IntNative = ", IntNative).
Regards
Martin

Posted: 27 Jan 2015 14:49
by Thomas Linder Puls
The descriptions in the language reference manual are a bit too simple to cover this situation.

It is polymorphism that complicates matters. In Visual Prolog a polymorphic value is always converted into something with the size of a pointer (4 bytes on 32bit platform, 8 on 64bit). This uniform size simplifies a lot of code and it also makes things more efficient than if all polymorphic code should expect different sizes.

In your case LowInt have type integer, so when you call the polymorphic predicate test_1 it will be converted into a pointer sized value. For integers this is the same as convert(integerNative, LowInt).

So in test_1 the Var variable have pointer size. sizeOf(Var) does however return the size of the "original" domain of Var (which is more useful since the "real" size is always sizeOfDomain(pointer)).

We (and others) use the phrase boxed values for such "uniformed values".

Posted: 27 Jan 2015 15:20
by Martin Meyer
I understand. Thank you!

Regards
Martin