comp.lang.ada
 help / color / mirror / Atom feed
* Error in gnat-4.6  (opensuse 11.4) ?
@ 2011-03-17 13:33 reinkor
  2011-03-17 14:34 ` Simon Wright
  0 siblings, 1 reply; 3+ messages in thread
From: reinkor @ 2011-03-17 13:33 UTC (permalink / raw)


Hello there,

I did strip down my program to the following (below) in order to
communicate
a possible error in gnat-4.6 (I use opensuse 11.4 on an hp Elitebook
6930p).
Could anybody try the same?

I get the following (test1.adb is listed below):

gnatmake -gnat2012 test1.adb
gcc -c -gnat2012 test1.adb
gnatbind -x test1.ali
gnatlink test1.ali
aaa > ./test1

raised STORAGE_ERROR : stack overflow (or erroneous memory access)

If I change:   "type Real is Digits 16;"  ->  "type Real is Digits
15;"
then I do not get "stack overflow".  Similarly, if I comment out for
example the statement " fe,xe : fe_t;"

reinert


------------------program listing-----------------
with Text_IO;
use  Text_IO;

with Ada.Numerics.Float_Random;
use  Ada.Numerics.Float_Random;
use  Ada.Numerics;

procedure test1 is

   type Real is Digits 16;

   G : Float_Random.Generator;

   type f_t  is array(1..0400) of Real;
   type fe_t is array(1..1000) of Real;

   type Node_t is
     record
        f, fm : f_t;
        fe,xe : fe_t;
        x  : Real;
     end record;

   Node : array (1..200) of Node_t;

   procedure initiate_nodes is
   begin
      for i in Node'range loop
          Node(i).x := Real(Float_Random.Random(Gen => G));
      end loop;
   end initiate_nodes;

begin

   Put( " Hello World! ");

end test1;



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Error in gnat-4.6  (opensuse 11.4) ?
  2011-03-17 13:33 Error in gnat-4.6 (opensuse 11.4) ? reinkor
@ 2011-03-17 14:34 ` Simon Wright
  2011-03-17 16:50   ` Jeffrey Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Wright @ 2011-03-17 14:34 UTC (permalink / raw)


reinkor <reinkor@gmail.com> writes:

> raised STORAGE_ERROR : stack overflow (or erroneous memory access)
>
> If I change:   "type Real is Digits 16;"  ->  "type Real is Digits
> 15;"
> then I do not get "stack overflow".  Similarly, if I comment out for
> example the statement " fe,xe : fe_t;"

>    type Real is Digits 16;

This (on Intel hardware) asks for what GNAT calls Long_Long_Float, which
requires 10 bytes. "digits 15" asks for Long_Float, which requires 8
bytes.

>    type f_t  is array(1..0400) of Real;
>    type fe_t is array(1..1000) of Real;
>
>    type Node_t is
>      record
>         f, fm : f_t;
>         fe,xe : fe_t;
>         x  : Real;
>      end record;
>
>    Node : array (1..200) of Node_t;

Node is declared on the stack, and uses 200*(400+400+1000+1000+1) =
560_000 Reals, which for Long_Float uses under 5MB of stack, for
Long_Long_Float uses just over and is probably the cause of your
reported stack_overflow.

You might be able to improve matters by using the ulimit command; it
didn't work here (Mac OS X). The only real way is to use heap
allocation:

   type Node_Array is array (Positive range <>) of Node_t;
   type Node_Array_P is access Node_Array;

   Node : Node_Array_P := new Node_Array (1..200);



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Error in gnat-4.6  (opensuse 11.4) ?
  2011-03-17 14:34 ` Simon Wright
@ 2011-03-17 16:50   ` Jeffrey Carter
  0 siblings, 0 replies; 3+ messages in thread
From: Jeffrey Carter @ 2011-03-17 16:50 UTC (permalink / raw)


On 03/17/2011 07:34 AM, Simon Wright wrote:
>
>>     type Real is Digits 16;
>
> This (on Intel hardware) asks for what GNAT calls Long_Long_Float, which
> requires 10 bytes. "digits 15" asks for Long_Float, which requires 8
> bytes.
>
>>     type f_t  is array(1..0400) of Real;
>>     type fe_t is array(1..1000) of Real;

Also note that GNAT might choose to align the components of these on 4-byte 
boundaries, making Fe_T 12_000 bytes rather than 10_000.

-- 
Jeff Carter
"We use a large, vibrating egg."
Annie Hall
44



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-03-17 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-17 13:33 Error in gnat-4.6 (opensuse 11.4) ? reinkor
2011-03-17 14:34 ` Simon Wright
2011-03-17 16:50   ` Jeffrey Carter

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