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-Thread: 103376,85c4b961f840b5ab X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Zero length Objects Date: Thu, 1 Jul 2004 15:52:29 +0100 Message-ID: <2kimpdF2orakU1@uni-berlin.de> References: <2oUEc.2$S77.1@nwrdny03.gnilink.net> X-Trace: news.uni-berlin.de 8SoI+sxUlytOczMTAW9VmQ8UD7QMzWUtlea6tfBSNN4kwOO0c= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Xref: g2news1.google.com comp.lang.ada:2027 Date: 2004-07-01T15:52:29+01:00 List-Id: "Frank J. Lhota" wrote in message news:2oUEc.2$S77.1@nwrdny03.gnilink.net... > "Brian May" wrote in message > news:sa41xjwy2nv.fsf@snoopy.apana.org.au... > > Is there any reason every object needs to have a unique address? > The issue is that if A and B share an address, then they are basically > aliases of each other, for no subprogram could distinguish between > them. The programmer, however, is declaring A and B as two > separate objects, so making them aliases would be a violation of the > author's intentions. I understand that the C and C++ standards mandate that all types (classes) must have a size greater than zero, for the reasons Frank gave. To expand on on his example a little, supposing we wrote a general-purpose termplate function which had to make sure its two parameters were not aliased: template function wibble(C* x, C* y) { if (x==y) raise Aliasing_Error; ... }; if we then had a class with no members: class CEmpty { ... }; CEmpty a, b; and tried to execute: wibble(&a,&b); we would wrongly get Aliasing_Error raised if a and b had been allocated to the same address. The rule that types (and so their objects) cannot be of zero size prevents this happening. To my mind, a significant problem remains. If we declared something like: CWhatever mem_a[1000000]; somewhere in a template class, where CWhatever was a template parameter, and then instantiated the class with CEmpty replacing CWhatever, we would get a mem_a in the instance that took up a whopping amount of memory to store absolutely nada! Yuk. PS: Please forgive any minor mistakes, I'm not a C++ expert. -- Nick Roberts