comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Address arithmetic alternatives
Date: Thu, 09 Jun 2011 13:25:58 +0200
Date: 2011-06-09T13:25:58+02:00	[thread overview]
Message-ID: <4df0adc6$0$6629$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <5bf3d787-c0b0-45c7-841f-0f08c93a3655@e26g2000vbz.googlegroups.com>

On 09.06.11 12:40, milouz wrote:
> 
>> More correctly, you *think* you need to play with address arithmetic. You may be
>> right, but address arithmetic is needed extremely rarely in Ada. Ada has
>> alternatives to most address arithmetic in C.
> 
> You're probably right. But what are those alternatives ?

I'd think array indexing (including ptrdiff_t stuff) is
a prominent example:

while (*s++) {
   ...
}

for K in S'Range loop
   ...
end loop;


Another is a C functions that reads two pointer, one a start
pointer and the other an offset pointer.

typedef ... t;

t* foo(const t* source, t* offset) { ...

In Ada, giving some more information about pointed to array
and the pointers via index ranges:

type T is ...;
type Indexing is range 0 .. Some_Maximum;
subtype Position is Indexing range 16#100# .. 16#1FF#;
subtype Distance is indexing
  range 0 .. Position'Last - Position'First;

type Array_of_T is array ( Position range <> ) of T;

function foo (Source : Array_of_T; Offset: Distance)
  return Distance;

(This doesn't mean that in C one couldn't write s[d], d++ or
that in Ada one couldn't use pointers with array components.
In fact, Ada.Containers features cursors. There is just much
expressive information in typed, constrained index values.
Depending on how much type information there is at compile
time, the compiler will reject a program if it can thus detect
a bounds violation (value not in type).)



  reply	other threads:[~2011-06-09 11:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-07 15:32 using `use' : what is the best practice ? milouz
2011-06-07 15:59 ` Simon Wright
2011-06-07 16:22 ` Dmitry A. Kazakov
2011-06-07 16:59   ` Simon Wright
2011-06-07 17:25     ` Dmitry A. Kazakov
2011-06-07 17:29       ` Simon Wright
2011-06-07 19:38         ` Dmitry A. Kazakov
2011-06-11 14:11           ` Yannick Duchêne (Hibou57)
2011-06-08  9:07       ` Paul Colin Gloster
2011-06-08 11:20         ` stefan-lucks
2011-06-08 16:45           ` Vinzent Hoefler
2011-06-11 14:05       ` Yannick Duchêne (Hibou57)
2011-06-07 17:33 ` Pascal Obry
2011-06-08  2:42   ` Randy Brukardt
2011-06-12  5:09   ` Yannick Duchêne (Hibou57)
2011-06-07 18:51 ` Jeffrey Carter
2011-06-08  0:04   ` Peter C. Chapin
2011-06-07 19:32 ` Anders Wirzenius
2011-06-07 23:38 ` Shark8
2011-06-12  5:19   ` Yannick Duchêne (Hibou57)
2011-06-12  7:55   ` Stephen Leake
2011-06-08  4:25 ` Jerry
2011-06-08  9:31   ` milouz
2011-06-08 17:17     ` Ludovic Brenta
2011-06-08 18:43     ` Jeffrey Carter
2011-06-09 10:40       ` Address arithmetic alternatives milouz
2011-06-09 11:25         ` Georg Bauhaus [this message]
2011-06-09 18:53         ` Jeffrey Carter
2011-06-08 19:22     ` using `use' : what is the best practice ? Pascal Obry
2011-06-09  1:17     ` Shark8
2011-06-09 10:44       ` milouz
2011-06-08  6:06 ` stefan-lucks
2011-06-15  2:25 ` Adrian Hoe
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox