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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cab230a084a14384 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Sun, 24 Jul 2005 13:22:28 -0500 Newsgroups: comp.lang.ada Subject: Re: ++ of C in ada References: <1122228917.377279.262690@g47g2000cwa.googlegroups.com> From: Ludovic Brenta Date: Sun, 24 Jul 2005 20:22:20 +0200 Message-ID: <87d5p8rrmr.fsf@tiscali.be> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:dNBuVCxFijgerOT5vv6qwmlsHkw= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 83.134.244.47 X-Trace: sv3-Yz83BJWHANlXgXBWDc7hGs9Ms/qmLcUQsQQqoyUJ8vRkfPKkS1rif5DI1MH3h/Rt/gBOlCE43GsUSYy!oUsJaehs6xk2pwkPYhvqBiDEVojGqFeIsUT1inASBoDlluqGW2OZ5wzzDD+13a8= X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:3744 Date: 2005-07-24T20:22:20+02:00 List-Id: "nicolas.b" writes: > How can i implement the operator ++ in ada : > > type T_Ptr is access all T_Item; > How can i implement : procedure Increment (Ptr : in out T_Ptr); > thanks Don't do this. In C, arrays and pointers are interchangeable, and pointer++ is used to traverse an array. In Ada, arrays and pointers are different. You cannot increment a pointer, but you can increment an array index: type T_Item_Array is array (Positive range <>) of T_Item; procedure Proc (A : in out T_Item_Array) is begin for J in A'Range loop A (J) := ... end loop; end Proc; The above demonstrates how Ada handles arrays of varying sizes, without the need for pointers (the compiler uses pointers behind the scenes, and also ensures you don't go past the end of the array, forget to deallocate your array, pass the wrong array size to Proc, or other such mistakes). If you are not doing arrays, the answer to your question is probably still "don't do this". If you explain what you are trying to do, we will explain the proper Ada way (or ways) of doing it. In general, pointer arithmetic is useful only when interfacing directly with your hardware. HTH -- Ludovic Brenta.