Re: ++ of C in ada
- From: Ludovic Brenta <ludovic.brenta@xxxxxxxxxx>
- Date: Sun, 24 Jul 2005 20:22:20 +0200
"nicolas.b" <nicolas.blanpain@xxxxxxxxxxxxxxxxxx> 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.
.
- References:
- ++ of C in ada
- From: nicolas.b
- ++ of C in ada
- Prev by Date: ++ of C in ada
- Next by Date: Re: ++ of C in ada
- Previous by thread: ++ of C in ada
- Next by thread: Re: ++ of C in ada
- Index(es):
Relevant Pages
|