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-30 22:02:06 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: <3B663BCD.A0CACD2@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> <9k517e$rbh$5@news.tpi.pl> <3B662129.D6055BAA@worldnet.att.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 31 Jul 2001 05:02:05 GMT NNTP-Posting-Host: 24.141.193.224 X-Complaints-To: abuse@home.net X-Trace: news1.rdc2.on.home.com 996555725 24.141.193.224 (Mon, 30 Jul 2001 22:02:05 PDT) NNTP-Posting-Date: Mon, 30 Jul 2001 22:02:05 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:10822 Date: 2001-07-31T05:02:05+00:00 List-Id: James Rogers wrote: > Tomasz Wegrzanowski wrote: > > In article <3B64C26F.C195B4E0@worldnet.att.net>, James Rogers wrote: > > > 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. > > > > Correct answer is compilation error. > > It's illegal to do pointer arith on void* or incomplete types. Yes, that is correct (that it is illegal). > It is illegal, but not necessarily caught by the compiler. > This means that the correct answer is not compilation error. > C compilers are actually pretty primitive in their understanding of > data type completion. They rely on highly intelligent linkers to > find all the completions. Unfortunately, linker diagnostic messages Huh? What does linking have to do with pointer arithmetic and "incomplete types"? I remember some bad C compilers (Aztec C on the Mac comes to mind), but even the ever forgiving HP C compiler would catch this kind of stuff (incomplete type and pointer arithmetic that is). As far as allowing "undefined pointer arithmetic" without a compiler warning or error, you need to cite specific compiler brands, and show examples. Otherwise this is just rubbish, as far as I can see. I've only seen error messages when pointer arithmetic is required for incompletely defined types. > If you do not TRULY know the type of the data pointed to by a void*, > and then you cast it to some type, expecting correct results, you > will sometimes get a nasty surprise. Pointer arithmetic will be > performed, but your view of the data will be incorrect due to > poor alignment problems. Of course. If you cast _any_ pointer to another pointer type, you cannot expect the arithmetic to be necessarily the same! So what's the point? All C programmers know this already. You as the C programmer have said "I know what I'm doing and I want you the compiler to treat this address as a pointer to type Z, and by golly, you better do pointer arithmetic according to the Z type." After that, are you really surprised that the C compiler generates code that does arithmetic on the pointer by type Z? > Jim Rogers > Colorado Springs, Colorado USA C compilers (as with the C language), do have "issues". But not the one you've chosen here. -- Warren W. Gay VE3WWG http://members.home.net/ve3wwg