Why isn't the address of an object of a schema type an acceptable value for a pointer to the (undiscriminated) schema type?
type sptr_type = ^ string ; type sptr_array_type( n : integer ) = array [ 1 .. n ] of sptr_type ; type sptr_array_ptr_type = ^ sptr_array_type ;
const s1 = 's1' ; const s2 = 's2' ; const s3 = 's3' ;
const slist : sptr_array_type(3) = ( @s1, @s2, @s3 ) ;
var slist_ptr : sptr_array_ptr_type = @slist ;
t12.pas:23: error: assignment from incompatible pointer type
I got the same error when I changed "slist" (the object of the discriminated schema type) from a "const" to a "var". I got the same error when I tried using an assignment statement:
var slp : sptr_array_ptr_type ; ... slp := @slist ;
If a discriminated instance of a schema type isn't quite the same type as the undiscriminated type, then when would I ever be able to use the address of an object as a value for a pointer to the undiscriminated type? (without coercion, that is)
On 13 Aug 2012 at 10:46, Jay Michael wrote:
Why isn't the address of an object of a schema type an acceptable
value for a pointer to the (undiscriminated) schema type?
type sptr_type = ^ string ; type sptr_array_type( n : integer ) = array [ 1 .. n ] of sptr_type ; type sptr_array_ptr_type = ^ sptr_array_type ;
const s1 = 's1' ; const s2 = 's2' ; const s3 = 's3' ;
const slist : sptr_array_type(3) = ( @s1, @s2, @s3 ) ;
var slist_ptr : sptr_array_ptr_type = @slist ;
t12.pas:23: error: assignment from incompatible pointer type
I got the same error when I changed "slist" (the object of the
discriminated schema type) from a "const" to a "var". I got the same error when I tried using an assignment statement:
var slp : sptr_array_ptr_type ; ... slp := @slist ; If a discriminated instance of a schema type isn't quite the
same type as the undiscriminated type, then when would I ever be able to use the address of an object as a value for a pointer to the undiscriminated type? (without coercion, that is)
Because what you are trying to do is rejected by the standards that you are implicitly following. Compile with "--no-typed-address", and it will compile.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Why isn't the address of an object of a schema type an acceptable
value for a pointer to the (undiscriminated) schema type?
type sptr_type = ^ string ; type sptr_array_type( n : integer ) = array [ 1 .. n ] of sptr_type ; type sptr_array_ptr_type = ^ sptr_array_type ;
const s1 = 's1' ; const s2 = 's2' ; const s3 = 's3' ;
const slist : sptr_array_type(3) = ( @s1, @s2, @s3 ) ;
var slist_ptr : sptr_array_ptr_type = @slist ;
t12.pas:23: error: assignment from incompatible pointer type
<snip>
If a discriminated instance of a schema type isn't quite the
same type as the undiscriminated type, then when would I ever be able to use the address of an object as a value for a pointer to the undiscriminated type? (without coercion, that is)
Of course discrimitated schema type and undiscriminated schema type are different types: discrimitated corresponds to a fixed tuple of discriminants and there is no way to change values of discriminants, while undiscriminated can be specialized to any legal discriminant values. In case of pointer types basice operation is passing pointer to 'new'. If 'p' is pointer to discrimitated schema type, then type contains values of discriminants and you pass just 'p' to 'new'. If 'p' is pointer to undiscrimitated schema type, then beside 'p' you also need to pass values of discriminants to 'new'. So usage is quite different.
One could argue that values having discrimitated schema type should be assignment compatible with undiscrimitated schema. However, Extended Pascal standard says otherwise.
Concerning using address operator to pass pointer to parameter having pointer to undiscrimitated schema type, I am affraid such usage was not considered when designing both features. Namely, schema types come from Extended Pascal and there is no address operator in Extended Pascal (in standard Pascal you are supposed to use var parameters instead). Address operator came from Borland Pascal. In Borland Pascal the only schema is the builtin 'string' schema and there are only discrimnated schema types (that is all strings in Borland Pascal must have declared maximal length (capacity)). So, given its Borland Pascal origin address operator produces pointers to discriminated schema types. Also, one may wish to get discriminated type. Given that convertion from pointer to discriminated schema to pointer to undiscriminated schema is more reasonable than convertion in opposite direction, it is reasonable that we get pointer to discriminated schema from address operator.
BTW. Both address operator and type coercions came from Borland Pascal and they are designed to be used together. So, do not be surprised that you need type coercion to type-check your usage of address operator.