Re: Pascal program file parameter to Ada translation (Was: Re: Is GPC dead?)

Kevan Hashemi <[email protected]> Thu, 05 Jan 2017 12:39:26 -0500
Newsgroups gmane.comp.compilers.gpc
Organization Brandeis University
Message-ID <[email protected]>
Leo: Thank you for your code example.

>    for i in 10 .. 20 loop
>       -- create xg on the stack (okay but stack size is limited)
>       -- xg exists only within this declare block
>       declare
>          xg : Array (0..i-1) of Float;
>       begin
>          Put (xg'last);
>          New_line;
>       end;
>    end loop;

That's the dynamic allocation I'm looking for, except it's on the stack. 
I need to use the main memory for dynamic allocation.

>       huge : Integer := 128_000_000;
>       xg_ptr : vector_ptr := new vector (0..huge);
>       xg     : vector renames xg_ptr.all;
>    begin
>       Put (xg'last);
>       New_line;
>       Free_Vector (xg_ptr);  -- essential to avoid memory leaks
>    end;

Here the size of the array is predefined with a constant "huge".

Bastiaan: Thanks for the link. In the linked code we have:

 >   VA     := new Vector (1 .. 10);
 >   VB     := VA;  -- points to the same location as VA

Here, the vector size is predefined with the constants 1 and 10.

Peter: Thank you for your FPC example, which does exactly what I need.

 > program A;
 > type
 > graph_type = array of real;
 > var
 >   xg:graph_type;
 >   i:integer;
 > begin
 >   for i:=100 to 200 do
 >   begin
 >     setlength(xg,i);
 >     xg := nil;
 >   end;
 > end.

Somehow, I missed setlength when I looked into FPC, and when I asked the 
FPC group about dynamic arrays, they must have interpreted my question 
as "does FPC support exactly the same syntax as GPC". So it looks like I 
could switch to FPC with minimal work.

Yours, Kevan


-- 
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/

_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc