Waldek Hebisch wrote:
Peter Schorn wrote:
Dear all,
while porting from CodeWarrior Object Pascal to GPC I noticed the following differences which might be worthwhile to address in GPC.
- Procedure type assignment compatibility with specialized parameters
program prog2; { compile with gpc --mac-pascal prog2.pas } type baseType = object end;
derivedType = object(baseType) end;
procedure p1(x: baseType); begin end; procedure p2(x: derivedType); begin end; var pv: procedure(x: baseType); begin pv := p1; pv := p2; { error: incompatible types in assignment } end.
A workaround is to declare the x in p2 as baseType and perform a cast in the body of p2.
Assigning p2 to pv is unsafe (I allows breaking type rules). Consider:
program unsafe; type baseType = object end;
derivedType = object(baseType) procedure m; end;
procedure derivedType.m; begin end;
var pv: procedure(x: baseType); v: baseType;
procedure p2(x: derivedType); begin x.m end;
begin new(v); pv := p2; { error: prevents wrong call } pv(v) end .
The only place which prevents wrong call is assignment to pv. Do CodeWarrior accept the program above?
[ ... ]
Thanks - I see. CodeWarrior compiles the program above without any error message but the program crashes when executed (not surprisingly anymore).
Peter Schorn mailto:peter.schorn@acm.org