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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a714625b3763f46e X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Modest proposal, 3 of 3 Date: 1996/11/26 Message-ID: #1/1 X-Deja-AN: 200866911 references: <575aq0$t4j@netline-fddi.jpl.nasa.gov> <32999420.53AA@lmtas.lmco.com> <57csa5$7c8@wdl1.wdl.lmco.com> organization: New York University newsgroups: comp.lang.ada Date: 1996-11-26T00:00:00+00:00 List-Id: >Van Snyder wrote: >> BACKGROUND >> This is OK, because there are only two things you can >> do with pointers (in a sane language): dereference them and copy them. I assume that this is a dig at the "pointer arithmetic" in C. If so, it is misguided. First, the rather surprising fact. Ada 95 has pointer arithmetic, C does not! Well that sounds outrageous, what do I mean by it? In C, a pointer is semantically a rather complex object, it is conceptually a pointer to an object in the usual manner, together with an offset into this object. So-called pointer arithmetic merely modifies the offset, and there is a restriction that the offset may not be adjusted to values outside the allocated object (with one small glitch that it is allowed to point just past the end of an array, generating a special pointer that cannot be dereferenced). Sure, a typical (but not required) implementation of C is to represent this semanti object with a single hardware pointer, and not to check for violation of the restrictions on the offset. This means that typical C *implementations* but not the C language itself, support completely general pointer arithmetic. But Ada 95 on the other hand supports quite general pointer arithmetic (see the type Integer_Address and its operations in System.Storage_Elements). Of course these are not everyday operations in Ada 95, and would be used only for certain purposes, e.g. computation of hash codes invlving pointers, or implementation of a garbage collector. But such tasks can be done in Ada 95 without going outside the semantics of the language. I was discussing the standard template library implementation with one of its authors a few months ago, and one of his complaints about C, and one of the things he liked about Ada 95, was the availability of general pointer arithmetic in Ada 95 that allowed certain algorithms involving hashing of pointers to be written completely portably in Ada 95 that could not be written in valid portable C.