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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4deb6c62a5e19f2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-29 19:36:02 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!enews.sgi.com!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc2.on.home.com.POSTED!not-for-mail Message-ID: <3B64C812.8CA53003@home.com> From: "Warren W. Gay VE3WWG" X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: type Foo_ptr in new void*; References: <9k03jc$2me$2@news.tpi.pl> <9k0j60$n4t$1@news.tpi.pl> <3B63F48A.2E2642C6@earthlink.net> <9k2btj$5hj$1@news.tpi.pl> <3B64C26F.C195B4E0@worldnet.att.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 30 Jul 2001 02:36:02 GMT NNTP-Posting-Host: 24.141.193.224 X-Complaints-To: abuse@home.net X-Trace: news1.rdc2.on.home.com 996460562 24.141.193.224 (Sun, 29 Jul 2001 19:36:02 PDT) NNTP-Posting-Date: Sun, 29 Jul 2001 19:36:02 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:10709 Date: 2001-07-30T02:36:02+00:00 List-Id: James Rogers wrote: > Tomasz Wegrzanowski wrote: > > In article <3B63F48A.2E2642C6@earthlink.net>, Marc A. Criley wrote: > > >> I can't do this. > > >> Foo is supposed to be used only as a pointer. > > >> I don't know if newer version of library will use the same Foo. > > > > > > In tmoran's post, wherever you saw "in out Foo", change it to "in > > > Foo_Pointer". > > > > > > In order to declare a pointer to a type, you have to have that type's > > > definition. Even C requires that for "foo*" there be some declaration > > > of "foo". > > > > Not true. > > You can use `struct Foo *' without declaring `struct Foo'. > > You can `typedef struct Foo Foo_t;' or `typedef struct Foo *Foo_p;' > > and use Foo_t and Foo_p w/o declaring `struct Foo'. > > Yes, you are correct. C does allow you to forward declare a structure > or a pointer without ever completing the definition. This is one of > the nasty capabilities "provided" by C. You can even create an array > of Foo *. However, pointer arithmetic from the start of this array > produces unspecified behavior. What is the sizeof Foo? Since it is > undefined, there is no correct answer to that question. Without a > proper definition of the sizeof Foo, there can be no reliable pointer > arithmetic. I don't think your "unspecified behavior" assertion is truly fair here. I believe that when you reach a point in the C/C++ compile where pointer arithmetic is required on the "undefined type", you will get a compile error. The compiler will not generate code that does "undefined behaviour" here. If there is any further doubt about it, I am sure this can be tested with a short example program. > In other words, you can declare some wonderful data structures in C > based on incomplete type definitions. Unfortunately, a program built > upon such a structure is neither reliable nor portable. Sad, but true. What sometimes happens, is that the C programmer wants the application to see an "opaque type", and so presents a different type to the user (by include file) than the original structure. If this "proxy" is incorrectly defined, its size can be wrong, causing of course, much "havoc" under the right circumstances. Ada of course, provides a better model for visibility. > Ada does not allow you to compile a program with an incomplete type > definition. There is no equivalent because the existence of an > equivalent to this C capability would only introduce errors in your > program. There is nothing positive that can be achieved by allowing > a program to be incompletely specified. Ada does permit you to define an incomplete type as well, but the condition is that it must be defined eventually. I agree that enforcing its later definition, is a good thing. -- Warren W. Gay VE3WWG http://members.home.net/ve3wwg