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!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: private types Date: 26 Mar 2006 13:53:48 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <1259548.CMTukHGvVZ@linux1.krischik.com> <9006286.GT9LdmDZaR@linux1.krischik.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1143399230 31117 192.74.137.71 (26 Mar 2006 18:53:49 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 26 Mar 2006 18:53:49 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:3636 Date: 2006-03-26T13:53:48-05:00 List-Id: Maciej Sobczak writes: > Robert A Duff wrote: > > >>>Only a very few C/C++ programmers > >>>actually master the language. > >> > >>As is true for any language that is at least moderately useful. > > True. Language designers ought to take that into account -- whenever > > possible, try to design features subtle misunderstandings are unlikely > > to cause bugs. > > True, I don't have any doubts about it. > > > Suppose an Ada programmer and a C++ programmer both think that null/NULL > > must be represented as all-zero-bits. Both programmers are confused. > > Both programmers take assumptions which are equally wrong. Right. > > But which programmer is more likely to write code that won't work > > on a machine where the assumption turns out to be false? > > Naither of those programmer should have any problems with their > programs, because pointers are, well, pointers, not integers. Neither of > them should have any temptation to interpret pointers as numbers, so > that the actual "value" of the pointer never really matters. You say "should". But we're talking about confused/wrong programmers. But the C++ programmer has been taught to use "0" as a value of type char* (which pointer value, of course, is not necessarily represented as all-zero-bits). See other posts in this thread, which recommend that style. It's not far from there, to (wrongly) believing that casting an integer zero to pointer will result in null. >... Even the > question "is the NULL pointer zero?" makes no sense in this light, > unless you target specific piece of silicon (see my replies to Martin > Krischik). I agree that the question "is the NULL pointer zero?" makes no sense, but the question "is the NULL pointer represented as zero (in some or all implementations of a certain language)?" makes sense. It's not usually a hardware ("silicon") issue, though. Ada compilers choose to represent null as zero because compilers for other languages do that, and because operating systems arrange for page zero to trap. Also, I think there are some minor efficiency advantages. > In practice, in the world of pointers it's not the NULL pointer > representation which is causing problems, but rather unconstrained > pointer arithmetics. Certainly pointer arithmetic adds extra trouble. But even without that, dereferencing of null pointers is a plentiful source of bugs. - Bob