From: Martin <martin.dowie@btopenworld.com>
Subject: Re: Allocation questions
Date: Thu, 28 May 2009 06:39:18 -0700 (PDT)
Date: 2009-05-28T06:39:18-07:00 [thread overview]
Message-ID: <78f30732-8d8d-4009-b9ed-ba19d275a5d9@f16g2000vbf.googlegroups.com> (raw)
In-Reply-To: 4a1e8454$0$2861$ba620e4c@news.skynet.be
On May 28, 1:32 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
wrote:
> 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 ?
Just remove the " := 0" bit.
> 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 ?
Works fine with 2_000_00 with GNAT GPL 2009 Win32... ;-)
What OS are you using?
Cheers
-- Martin
next prev parent reply other threads:[~2009-05-28 13:39 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
2009-05-28 13:39 ` Martin [this message]
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