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,61006929d3e14455 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: Ada Pointer Size Problem Message-ID: References: <35f054ea.0410101150.25bec2f5@posting.google.com> <6Joad.8869$UP1.8086@newsread1.news.pas.earthlink.net> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 01 Nov 2004 08:14:03 GMT NNTP-Posting-Host: 12.75.206.96 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1099296843 12.75.206.96 (Mon, 01 Nov 2004 08:14:03 GMT) NNTP-Posting-Date: Mon, 01 Nov 2004 08:14:03 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:5948 Date: 2004-11-01T08:14:03+00:00 List-Id: On Thu, 21 Oct 2004 01:56:28 GMT, Jeffrey Carter wrote: > Dave Thompson wrote: > > > On Mon, 11 Oct 2004 05:18:58 GMT, Jeffrey Carter > > wrote: > >> > >> In C/++, a pointer is an int is an address. In Ada, they're 3 > >> different things. > > > > But (unlike its predecessor B) a C pointer/address is not just an > > int. > > I meant that a pointer is an int because you can always convert/assign a > pointer to an int. Well, in many languages (not just C) you can just assign an integer (or fixed-point) value to floating-point and vice versa, but I sure wouldn't say that either "is" the other. And you can't assign C pointer to integer without conversion; it violates a constraint. (Or pass as parameter or return as value, since in C those are always semantically equivalent to assignment.) You can write the conversion to any integer type explicitly with a cast, but the result is implementation-defined and may or may not be useful. For most mainstream systems there is a simple and useful mapping and that is what any sensible implementation provides, but the Standard doesn't require it. As others have already said, the specific type 'int', which is only one of the integer types provided by a conforming C, need not be large enough to handle (all) addresses. In addition to the 286 example, I have long personal experience of the "classic" (that is, pre-RISC, still used in emulation) Tandem^WCompaq^WHP NonStop, with three execution models: IP16, I16P32, and IP32; corresponding basically to different stages in their CPU/ISA evolution. In the "large" I16P32 model obviously pointer in int doesn't work. The new-in-C99 names intptr_t and uintptr_t are integer types guaranteed large enough to losslessly store (with the explicit conversion) any (data) pointer, but are optional; an implementation need not provide them if it doesn't have a suitable integer type. As with all the new types, there is an associated preprocessor macro you can test to determine if the type is present, and thus write code that works-around the omission or at least fails gracefully -- but only with the ugliness typical of preprocessor solutions, as often discussed here. But machines that actually can't do address arithmetic -- and thus reasonably support such an integer type -- are for obvious reasons pretty damn rare if they exist at all, and also (would be) very unlikely to be able to support the rest of C anyway. - David.Thompson1 at worldnet.att.net