Peter N Lewis wrote:
What facilities does GPC have for forward defining types.
In CW Pascal, I have some code that looks like this:
type MyProc = procedure( browser: MyObjectA ); MyObjectA = object f: MyProc; b: MyObjectB; procedure Doit( proc: MyProc ); function GetB: MyObjectB; end; MyObjectB = object; f: MyObjectA; // other references to ObjectA end;
Keep in mind all the "used before defined" types are pointer types (objects being implicitly pointers) and defined in the same "type" block.
GPC is not happy with this. Needless to say, given the dual referential nature of the references, it is hard to see how I can cleanly untangle this.
Is there any support in GPC or EP for these kinds of forward defined types?
EP only supports explicit pointers. These objects are implicit pointers (or references), as you know.
For explicit pointers, there's a provision in standard Pascal (and all dialects I know of), so there is no problem there. (And that's what GPC currently supports.) You just declare pointer types to the object types before the object types themselves and before MyProc.
Implicit references present a new problem here. ATM, I don't see a really nice solution. Allowing forward referencing of any type would be both difficult to implement and IMHO bad style, weakening Pascal's principles.
Looking at OOE ... AFAICS, their solution to this problem is the following:
: 6.1.5 Deferred class definitions. : : A class name can be declared before its structure and contents are defined. : This is specified by: : : TYPE : name = [ kind ] CLASS .. END; : : NOTE: In the above, ".." is a symbol. : : Later in the same type-definition-part, there must be a type definition with : the same name that specifies the contents and structure of the class. A class : cannot be used in a class-inheritance-list before its complete definition is : specified.
I think this could be reasonable. Similarly to a forward-defined pointer type, this forward-defines a reference type.
We could probably add the same with `object' references. (Waldek?)
Frank