Re: schema pointer compatibility

Waldek Hebisch <[email protected]>
Newsgroups gmane.comp.compilers.gpc
Message-ID <[email protected]>
> 
>      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.

-- 
                              Waldek Hebisch
[email protected] 

_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.