Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
From: Peter Schorn
Subject: GPC and CodeWarrior Object Pascal
Date: 20 Apr 2006, 18:46:32
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.
>>
>>
>> 2) 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
Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
| Author | Subject | Date |
|---|---|---|
| Waldek Hebisch | GPC and CodeWarrior Object Pascal | 19 Apr 2006, 23:50:47 |
Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.
Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.
This page was created by Crystal 0.999 (Linux 2.4.27/i686).