GNU Pascal Homepage - gpc - gpc-announce - gpc-de - gpc-doc
Diese Seite auf deutsch

Mail #12370

Back to main page of archive

Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  

From: Gale Paeper
Subject: Forward defined types (and object references)
Date: 7 Jul 2005, 00:36:32

Waldek Hebisch wrote:
> 
> Peter N Lewis wrote:
[snip]
> >
> > No, CW does not accept either syntax:
> >
> > MyObject = object;
> > nor
> > MyObject = object .. end;
> >

In case it helps, CodeWarrior Pascal (as well as MPW Pascal) also
supports a forward directive declaration form for objects, i.e,:

 MyObject = object; forward;

A test program using a slightly modified expample from CodeWarrior
Pascal's documentation:

program ForwardObjectTest;

type	
  objA = object;forward;
  objB = object
    {...}
    o : objA; { objB uses objA }
    {...}
  end;
  
{var
  dummy: integer;

type}
  objA = object
    {...}
    p : objB; { objB uses objA }
    {...}
  end;    
begin
end.

The forward object type declaration must have a complete type
declaration in the same type declaration part (like Pascal's requirement
for pointer types).  The commented out var declaration part and type
keyword is what I used to test that requirement. Uncomment that part and
you get:

Error   : unresolved forward class reference to 'objA'
ForwardObjectTest.p line 11   var


> > CW takes the approach that any unknown type identifier it sees in a
> > type definition is pointer sized (a pointer or object) and must be
> > defined by the end of the type block.
> >
> >    type
> >      rec = record
> >        a: UndefinedA;
> >        b: UndefinedB;
> >      end;
> >      UndefinedA = ^Integer;
> >      UndefinedB = object
> >      end;
> >
> > Note that UndefinedA = UInt32 is not legal, it must be a pointer or object.
> >
> > It's actually not a bad methodology and makes it easy to write data
> > structures that is self or mutually referential, but it does not add
> > anything over pre defining pointers or object names as EP/Delphi.
> >
> 
> Does it allow the same in nested scopes? AFAIU objects are not allowed in
> nested scopes, but pointers still make sense. Also, what happens if the name
> is a predefined type (or a name declared in outer scope)? Normal Pascal rules
> are that the new definition should be used (even if the definition follows use),
> are they obeyed?

CodeWarrior Pascal doesn't correctly handle nested scope forward pointer
redeclarations and you need some additional erroneous code construct
(such as a type mismatch) for the compiler to report an error. A snippet
inserted into the above test program:

type  
  UndefinedA = ^Integer;

procedure test;

type
    rec = record
      a: UndefinedA;
    end;
    UndefinedA = ^boolean;
    
var
  testrec : rec;
begin
  new(testrec.a);
  testrec.a^ := true;
end;

yields:

Error   : type mismatch
ForwardObjectTest.p line 36   testrec.a^ := true;

which indicates the compiler is incorrectly using the outer scope
declaration for UndefinedA when compiling the inner scope rec type.

In fairness, I'll note CodeWarrior Pascal isn't the only Pascal compiler
I've used that has problems in correctly handling nested scope use
before redeclaration cases.
 
Gale Paeper
gpaeper@empirenet.com

Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  


Replies

Author Subject Date
Frank Heckenbach Forward defined types (and object 7 Jul 2005, 12:50:57
Gale Paeper Forward defined types (and object 7 Jul 2005, 19:27:24
Frank Heckenbach Forward defined types (and object 8 Jul 2005, 12:01:27

In reply to

Author Subject Date
Waldek Hebisch Forward defined types (and object references) 6 Jul 2005, 20:41:10

Back to main page of archive


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).