Re: [CS3304_1381] forward type declaration

New Message Reply About this list Date view Thread view Subject view Author view

Stephen Edwards (edwards@CS.VT.EDU)
Mon, 14 Feb 2000 09:06:09 -0500


Message-ID:  <38A80BD1.66F53825@cs.vt.edu>
Date:         Mon, 14 Feb 2000 09:06:09 -0500
From: Stephen Edwards <edwards@CS.VT.EDU>
Subject:      Re: [CS3304_1381] forward type declaration

> The compiler
> won't let me put pointers to the record in the record definition.

Correct. You need to give a name to the pointer type (it cannot be
anonymous). As you correctly conclude, you need something like a
"forward declaration" for a type.

> Is there
> any way to use the forward keyword in Pascal to accomplish this?

In Pascal, the "forward" keyword is for procedure/function declarations.
For types, this situation only occurs with pointers. The following is the
correct Pascal approach (slightly modified from your example):

    type
        NodePtr = ^NodeType;
        NodeType = record
            lchild, rchild : NodePtr;
        end;

In this case, the first occurance of "NodeType" in the definition of
NodePtr is a forward reference. Pascal knows that it needs to figure
out what that name refers to in a later type declaration, and will
complain if it doesn't see it anywhere.

                                -- Steve

--
Stephen Edwards            641 McBryde Hall          Dept. of Computer Science
e-mail      : edwards@cs.vt.edu           U.S. mail: Virginia Tech (VPI&SU)
office phone: (540)-231-5723                         Blacksburg, VA  24061-0106
-------------------------------------------------------------------------------


New Message Reply About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b3 on Mon Feb 14 2000 - 09:06:52 EST