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!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed-0.progon.net!progon.net!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: private types Date: Tue, 21 Mar 2006 08:41:57 +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> <4672587.DAoJQAFo3c@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 1142926917 29530 (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: <4672587.DAoJQAFo3c@linux1.krischik.com> Xref: g2news1.google.com comp.lang.ada:3515 Date: 2006-03-21T08:41:57+01:00 List-Id: Martin Krischik wrote: >>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. > > For C++ I can - barely - see that but C is supposed to system programming > language suitable for kernel and/or embedded progamming. Taking that into > account: How actually are the languages implementers to implement > "distinct from any other valid pointer". Any way they want. > If you are implementing a Ring 0 > device driver on x86 all pointers are valid and on PC architecture there is > memory at (void*0) which one might want to access. The point is that if you are writing software for some specific piece of hardware, then handling of NULL is the least of your problems. You need extensive knowledge and guarantees, considering, among others, stuff like word sizes, alignment, byte ordering, representation and existence of trap values, etc. In other words, you don't just pick any compiler at random, but rather you use the one which gives you the set of required guarantees. And among those guarantees there will be something about the NULL pointer. Most likely you will just know that the NULL pointer has representation of all bits zero. Note also that in so called reality compilers that do not implement NULL as zero just do not sell very well. This is because many C programmers are used to do this: struct S { int x; char *p; /* ... */ }; struct S s; memset(&s, 0, sizeof(S)); /* <- here */ and later expect that s.p == NULL; The "idiom" of memsetting structures is so deeply rooted in the C community that you can find it in almost every C program and most C books. It's clear that the "idiom" bypasses the typesafety of fields by just plowing over their underlying representation, and this can work only with those compilers that do not exercise the full freedom that the standard gives them. So - no worry. It just works. :) -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/