From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1901f265c928a511 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Typing in Ada From: James Rogers References: <40BDBBFA.2020203@noplace.com> <1087475285.166449@master.nyc.kbcfp.com> Message-ID: User-Agent: Xnews/5.04.25 Date: Thu, 17 Jun 2004 23:42:55 GMT NNTP-Posting-Host: 12.73.183.236 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1087515775 12.73.183.236 (Thu, 17 Jun 2004 23:42:55 GMT) NNTP-Posting-Date: Thu, 17 Jun 2004 23:42:55 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:1637 Date: 2004-06-17T23:42:55+00:00 List-Id: Hyman Rosen wrote in news:1087475285.166449@master.nyc.kbcfp.com: > No, incomplete types in C have nothing to do with linking. > Incomplete types are there for the same reason as in any > other language, so that mutually recursive types may be > declared. Eg., > struct A; > struct B { struct A *my_A; int x; }; > struct A { struct B *my_B; int y; }; > For this mutual recursion to be possible, C and C++ must > then identify the places where incomplete types may be used, > such as in declarations of pointers to them, or as function > parameters - basically those places where knowing the innards > of the type is unnecessary. > > It is true in C or C++ that if you never have a context in > which you need the complete type, you need not supply it, > even at link time. Perhaps I misspoke. I did not mean that C reserves incomplete types for link time. I meant to say that the compiler does not require completion of incomplete types. This effect allows a C program to define an incomplete type in the global area of one file and complete the type in another file. The compiler never knows of the completion, while the linker might. I agree that the most common use of incomplete types is the same in C as in Ada; for recursive or self-referential types. One common example is a singly linked list, where one of the node data elements is a reference or pointer to the next node. A common Ada implementation approach is: package Single_List is type List is private procedure add(Item : in Item_Type; To : in out List); procedure get(Item : out Item_Type; From : in out List); function Is_Empty(The_List : List) return Boolean; private type Node; type List is Access Node; Type Node is record Element : Item_Type; Next : List := Null; end record; end Single_List; The Ada difference is that all incomplete types must be completed in the same compilation unit. Jim Rogers