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,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!peer01.cox.net!cox.net!p01!fed1read01.POSTED!53ab2750!not-for-mail From: James Dennett User-Agent: Thunderbird 1.5 (Macintosh/20051201) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: private types References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <1259548.CMTukHGvVZ@linux1.krischik.com> <1172812.9zPbPKbdVq@linux1.krischik.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Mon, 20 Mar 2006 08:47:13 -0800 NNTP-Posting-Host: 68.7.248.4 X-Complaints-To: abuse@cox.net X-Trace: fed1read01 1142873202 68.7.248.4 (Mon, 20 Mar 2006 11:46:42 EST) NNTP-Posting-Date: Mon, 20 Mar 2006 11:46:42 EST Organization: Cox Communications Xref: g2news1.google.com comp.lang.ada:3496 Date: 2006-03-20T08:47:13-08:00 List-Id: Robert A Duff wrote: > Maciej Sobczak writes: > >> but still, (void*)0 == NULL will always evaluate to true, even if the >> internal representation of the null pointer is not zero. > > Are you sure? Are you talking about C or C++ or both? It's true for both, given the right interpretation of (void*)0. > Does (void*)x always return NULL if x is an appropriate-sized integer > whose value is zero? Not necessarily. But if x is a null pointer constant, which to C++ means an integral constant expression with value zero, then it will. (C also allows an ICE of zero cast to void*, so you have a NPC already.) > That would require run-time overhead if > NULL is not represented as all-zero-bits. Yes, but that's not required. You can get different behaviour from int i(0); void *p((void*)i); than from int const i(0); void *p((void*)i); because for C++ the latter i is a valid integral constant expression, while the former is not. > On the other hand, it's pretty confusing if casting zero to (void*) > is sometimes guaranteed to return NULL, and sometimes not, depending > on whether the zero value is known at compile time. Afraid so; generally C++ is arranged so that removing const, where legal, should not change the meaning of code -- but this is an exception, in theory at least. -- James