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!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed-east.nntpserver.com!nntpserver.com!statler.nntpserver.com!newspeer1.nwr.nac.net!solnet.ch!solnet.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: private types Date: Mon, 20 Mar 2006 10:57:01 +0100 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <1259548.CMTukHGvVZ@linux1.krischik.com> <1172812.9zPbPKbdVq@linux1.krischik.com> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1142848621 23046 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060203 Red Hat/1.7.12-1.1.3.4 X-Accept-Language: en-us, en In-Reply-To: <1172812.9zPbPKbdVq@linux1.krischik.com> Xref: g2news1.google.com comp.lang.ada:3477 Date: 2006-03-20T10:57:01+01:00 List-Id: Martin Krischik wrote: >>Well, does the standard require that (void*)0 == NULL? > > Before I learned C++ in deeps I thought the same. But then I read that the > use of #define NULL is depreciated C++ and that one should use a simple 0 > instead. Where did you read this? NULL is not depreciated. It's defined in the header to be a null-pointer constant, which is any integral const expression that evaluates to 0. Possible definition is: #define NULL 0 Note: the following is explicitly prohibited: #define NULL (void*)0 but still, (void*)0 == NULL will always evaluate to true, even if the internal representation of the null pointer is not zero. >>What if I wanted >>a pointer to address zero on this hypothetical OS? > > That too is an interesting point. Actually dereference to (char*)0 is not > forbidden - you will get the content of memory element 0x0. Not necessarily. It depends on what is the internal representation of the null pointer. One of the possible ways to *really* get at address 0x0 is to do reinterpret_cast or use a union with the same effect. Usual cast notation as the one above will not do. >>How would I get that >>if (void*)0 gets transformed to a non-zero NULL? > > Interesting question. The interesting question is why it might make any difference to you? The only thing that really matters is that the null pointer is distinct from any other valid pointer, in which case it's equivalent to Ada's null. If you need more knowledge than this, then either you are doing something wrong, or you work in the application domain where you really need an intimate knowledge of all the parts of the underlying platform - including your compiler - in which case your above worries are gone anyway. -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/