comp.lang.ada
 help / color / mirror / Atom feed
From: Olivier Scalbert <olivier.scalbert@algosyn.com>
Subject: Re: Allocation questions
Date: Thu, 28 May 2009 14:32:01 +0200
Date: 2009-05-28T14:32:01+02:00	[thread overview]
Message-ID: <4a1e8454$0$2861$ba620e4c@news.skynet.be> (raw)
In-Reply-To: <40a2a911-6b92-407e-b1e3-deabf154892f@x6g2000vbg.googlegroups.com>

Martin wrote:
> On May 28, 11:05 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>

> 
> p.s. here's a demo:
> 
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Demo is
>    package D is
>       type No_Of_Samples is range 0 .. 1_000;
>       type A_of_F is array (No_Of_Samples range <>) of Float;
>       type R (S : No_Of_Samples := 0) is private;
>       function Create (N : No_Of_Samples) return R;
>       procedure Put_Line (This_R : R);
>    private
>       type R (S : No_Of_Samples := 0) is
>          record
>             I : Integer;
>             B : Boolean;
>             A : A_Of_F (1 .. S);
>          end record;
>    end D;
>    package body D is
>       function Create (N : No_Of_Samples) return R is
>       begin
>          return (S => N,
>                  I => 0,
>                  B => False,
>                  A => (others => 0.0));
>       end Create;
>       procedure Put_Line (This_R : R) is
>       begin
>          Put_Line (Integer'Image (This_R.I));
>          Put_Line (Boolean'Image (This_R.B));
>          Put_Line (No_Of_Samples'Image (This_R.S));
>          for I in This_R.A'Range loop
>             Put_Line (Float'Image (This_R.A (I)));
>          end loop;
>       end Put_Line;
>    end D;
> 
>    R_1 : D.R := D.Create (1);
>    R_5 : D.R := D.Create (5);
> begin
>    D.Put_Line (R_1);
>    D.Put_Line (R_5);
> end Demo;

Thanks Martin, it works!

2 more questions:

1) In fact (due to my background!), I would like to use the dot notation:
object.method.
So I have add "tagged":

     type Delay_Type (Size : Nb_Of_Samples := 0) is tagged private;
     ...
private
     type Delay_Type (Size : Nb_Of_Samples :=0) is tagged record
      ...

When I compile, I have:
"discriminants of tagged type cannot have defaults"
How can I fix it ?

2) If Nb_Of_Samples range is too large, around 1..5_000_000, I have a 
nice Segmentation fault. How can I fix that ?

Thanks

Olivier







  reply	other threads:[~2009-05-28 12:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-28  9:46 Allocation questions Olivier Scalbert
2009-05-28 10:02 ` Martin
2009-05-28 11:55   ` xavier grave
2009-05-28 12:19     ` Ludovic Brenta
2009-05-28 13:00       ` Georg Bauhaus
2009-05-28 23:13       ` Robert A Duff
2009-05-28 10:05 ` Dmitry A. Kazakov
2009-05-28 10:40   ` Martin
2009-05-28 12:32     ` Olivier Scalbert [this message]
2009-05-28 13:39       ` Martin
2009-05-28 13:57         ` Olivier Scalbert
2009-05-28 14:51         ` Adam Beneschan
2009-05-28 17:58           ` Randy Brukardt
2009-05-28 14:04       ` Dmitry A. Kazakov
2009-05-28 16:59 ` Jeffrey R. Carter
2009-05-28 17:26   ` Olivier Scalbert
replies disabled

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