comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <jrcarter@acm.org>
Subject: Re: Why does this work? (overloads)
Date: Thu, 08 Feb 2007 18:52:20 GMT
Date: 2007-02-08T18:52:20+00:00	[thread overview]
Message-ID: <EjKyh.337223$FQ1.193991@attbi_s71> (raw)
In-Reply-To: <1170931228.165961.8170@m58g2000cwm.googlegroups.com>

Jerry wrote:
>>
> Good point. However, it uses twice the memory, and worse, changes made
> in A are not reflected in B without repeating the assignment A := B
> (correct?) and vice versa. My Pascal trick had neither of these
> problems yet carried boundary checking using either name.

Right. But your Pascal trick is an abomination. You can do the same 
thing in Ada using overlays, but it's not recommended. There's probably 
also a way with access types. Something like (not tested)

type Vector is array (Natural range <>) of Real;

Max : constant := ...;

subtype Zero_Based is Vector (0 .. Max - 1);
subtype One_Based  is Vector (1 .. Max    );

type Zero_Ptr is access all Zero_Based;
type One_Ptr  is access all One_Based;

V : aliased Zero_Based;

ZP : Zero_Ptr := V'access;

function To_One is new Ada.Unchecked_Deallocation
    (Source = Zero_Ptr, Target => One_Ptr);

OP : One_Ptr := To_One (ZP);

I wouldn't recommend it.

-- 
Jeff Carter
"What I wouldn't give for a large sock with horse manure in it."
Annie Hall
42



  parent reply	other threads:[~2007-02-08 18:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-07  4:39 Why does this work? (overloads) Jerry
2007-02-07  6:45 ` AW: " Grein, Christoph (Fa. ESG)
2007-02-07  7:07   ` Jerry
2007-02-07  7:26     ` AW: " Grein, Christoph (Fa. ESG)
2007-02-07 20:43       ` Jerry
2007-02-07 19:09   ` AW: " Jeffrey R. Carter
2007-02-07 21:13     ` Jerry
2007-02-07 21:33       ` Ludovic Brenta
2007-02-07 21:36       ` Randy Brukardt
2007-02-07 19:02 ` Jeffrey R. Carter
2007-02-07 19:21   ` Adam Beneschan
2007-02-07 19:25     ` Adam Beneschan
2007-02-08  0:51       ` Jeffrey R. Carter
2007-02-07 23:12     ` Robert A Duff
2007-02-08  0:49     ` Jeffrey R. Carter
2007-02-07 20:53   ` Jerry
2007-02-08  0:53     ` Jeffrey R. Carter
2007-02-08 10:40       ` Jerry
2007-02-08 11:34         ` Georg Bauhaus
2007-02-08 12:05         ` AW: " Grein, Christoph (Fa. ESG)
2007-02-08 18:52         ` Jeffrey R. Carter [this message]
2007-02-09  0:56         ` Jerry
2007-02-09  1:27         ` tmoran
replies disabled

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