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: a07f3367d7,9506bdc34331969a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!209.197.12.246.MISMATCH!nx02.iad01.newshosting.com!newshosting.com!novia!transit3.readnews.com!news-xxxfer.readnews.com!news-out.readnews.com!transit4.readnews.com!panix!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: put of access type Date: Thu, 20 Aug 2009 16:57:49 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <8sho8596j3qnja38id9ipejk0opkcn5b5m@4ax.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1250801869 23803 192.74.137.71 (20 Aug 2009 20:57:49 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 20 Aug 2009 20:57:49 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:/7bglYIJdRHlEEcq3w/ru0WKFnI= Xref: g2news2.google.com comp.lang.ada:7919 Date: 2009-08-20T16:57:49-04:00 List-Id: Rob Solomon writes: > I see that access types are being used the same as pointer types, but > if I understand correctly, are actually quite different. But I don't > understand how. ie, how are access types and pointers different? It depends on what you mean by "pointer". Yes, "access types" in Ada are pretty much the same as "pointer types" in many other languages. They are used primarily to point to heap-allocated data structures (linked lists, trees, etc). There are differences between Ada's access, and Pascal or Modula-2's pointer. But they are minor. The differences between Ada and C in this area area larger (in particular, C uses pointers for by-hand-by-reference parameter passing, and for cursors within arrays (incrementing a pointer to an array element in C causes it to point to the next element) -- no such thing in Ada). Some folks in this thread have emphasized the fact that in Ada, an access value is not necessarily represented as a (single) machine address. That's true. But the same is true of many other languages, including even C. > What is the difference between integer_address and address? They're completely different. I think you're going about this in a wrong way. I presume you want to learn Ada, and in particular you want to learn how to use Ada's access types. Is that correct? If so, you should (at first) avoid any use of "aliased" or 'Access. You should avoid pretty much everything in chap 13 of the RM, including Address, Integer_Address, 'Address, operations on addresses. Instead, focus on linked lists and trees and other heap-based data structures. And understand access values by drawing pictures with boxes and arrows. That's how I learned about pointers in Pascal. Nothing wrong with printing out an access value for debugging (or understanding) purposes. I showed you an easy way to do that in GNAT (Address_Image). But don't focus on that. Later on, learn about aliased and 'Access and 'Unchecked_Access. And later still, learn about chap 13 stuff, like type Address. > I need help with this code: > > procedure adr is > > c: integer; > x: aliased integer; > p1, p2 : access integer; > str : string (1..255); > > Begin > p1 := x'access; > p2 := p1; > str := integer_address'image(to_integer(p1.all'address)); > c := integer(to_integer(p2.all'address)); > > some put statements > end adr; > > This compiles w/ GNAT under Ubuntu 9.04, but I am getting > constraint_error, range check failed. > > I don't understand why In Ada, "string (1..255)" means a String of _exactly_ 255 characters. Not a string of "at most" 255 characters. - Bob