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: 103376,f5c6fba20eff3d07 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!feeder.news-service.com!216.196.110.148.MISMATCH!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder2.news.saunalahti.fi!newsfeed2.fi.sn.net!fi.sn.net!newsfeed1.fi.sn.net!news.song.fi!not-for-mail Date: Tue, 16 Oct 2007 17:09:18 +0300 From: Niklas Holsti User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20060628 Debian/1.7.8-1sarge7.1 X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Pointer to Array References: <1192542030.745091.64900@q5g2000prf.googlegroups.com> In-Reply-To: <1192542030.745091.64900@q5g2000prf.googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4714c406$0$27840$39db0f71@news.song.fi> Organization: TDC Song Internet Services NNTP-Posting-Host: laku61.adsl.netsonic.fi X-Trace: 1192543238 news.song.fi 27840 81.17.205.61:32877 X-Complaints-To: abuse@song.fi Xref: g2news2.google.com comp.lang.ada:2464 Date: 2007-10-16T17:09:18+03:00 List-Id: shaunpatterson@gmail.com wrote: > I'm attempting to make a pointer to an array... or in a sense > "rename" an array. > > I'm combining code from two very similar systems. Lots of code. > > I have thousands of lines of code that's exactly the same, using > (for just an example) an array of Integers. > > There is a store file in each system that declares: > > -- system 1 > type INT_ARRAY is new Integer (1..SYSTEM_1_SIZE); That declaration of INT_ARRAY is not correct -- you must have made a typo of some sort in writing your post. What is the real declaration? > I want to keep that code untouched if possible. I'm hoping there is a > way > in Ada to do something like > > type INT_ARRAY is array (Positive range <>) of Integer; > Int_Array_Var_System1 : INT_ARRAY (1..System_1_Size); > Int_Array_Var_System2 : INT_ARRAY (1..System_2_Size); > > > And I'd like to so something at run time that is like: > > if usingSystem1 then > Int_array_Var = "pointer to Int_Array_Var_System1" > elsif usingSystem2 then > Int_array_Var = "pointer to Int_Array_Var_System2" > > by changing the pointer I'm hoping to keep most of existing code the > same. > > Is there any method in ada to do this? Better method: Make the the code into a procedure that takes the parameter as an array, then call the procedure either with Int_Array_Var_System1 or Int_Array_Var_System2 as the actual parameter. But this can be difficult if you have several such pairs of arrays, and the condition for choosing system1/2 is not the same for all pairs -- you can get a large number of combinations. Second method, using an access variable (the Text_IO and Command_Line are there just for testing): with Ada.Text_IO; with Ada.Command_Line; procedure IntArr is type INT_ARRAY is array (Positive range <>) of Integer; System_1_Size : constant := 55; System_2_Size : constant := 77; Int_Array_Var_System1 : aliased INT_ARRAY := (1..System_1_Size => 0); Int_Array_Var_System2 : aliased INT_ARRAY := (1..System_2_Size => 0); type INT_ARRAY_REF is access all INT_ARRAY; Int_Array_Var : INT_ARRAY_REF; begin if Ada.Command_Line.Argument_Count > 0 then Int_Array_Var := Int_Array_Var_System1'Access; else Int_Array_Var := Int_Array_Var_System2'Access; end if; Ada.Text_IO.Put_Line ( "Length" & Natural'Image (Int_Array_Var'Length)); end IntArr; HTH... -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .