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: a07f3367d7,4cad17e8664256c9 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!f16g2000vbf.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Allocation questions Date: Thu, 28 May 2009 06:39:18 -0700 (PDT) Organization: http://groups.google.com Message-ID: <78f30732-8d8d-4009-b9ed-ba19d275a5d9@f16g2000vbf.googlegroups.com> References: <4a1e5d9e$0$2868$ba620e4c@news.skynet.be> <106ssailgl19b$.1sngvazrm7u5w.dlg@40tude.net> <40a2a911-6b92-407e-b1e3-deabf154892f@x6g2000vbg.googlegroups.com> <4a1e8454$0$2861$ba620e4c@news.skynet.be> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1243517958 32251 127.0.0.1 (28 May 2009 13:39:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 28 May 2009 13:39:18 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f16g2000vbf.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6071 Date: 2009-05-28T06:39:18-07:00 List-Id: On May 28, 1:32=A0pm, Olivier Scalbert wrote: > Martin wrote: > > On May 28, 11:05 am, "Dmitry A. Kazakov" > > > p.s. here's a demo: > > > with Ada.Text_IO; use Ada.Text_IO; > > procedure Demo is > > =A0 =A0package D is > > =A0 =A0 =A0 type No_Of_Samples is range 0 .. 1_000; > > =A0 =A0 =A0 type A_of_F is array (No_Of_Samples range <>) of Float; > > =A0 =A0 =A0 type R (S : No_Of_Samples :=3D 0) is private; > > =A0 =A0 =A0 function Create (N : No_Of_Samples) return R; > > =A0 =A0 =A0 procedure Put_Line (This_R : R); > > =A0 =A0private > > =A0 =A0 =A0 type R (S : No_Of_Samples :=3D 0) is > > =A0 =A0 =A0 =A0 =A0record > > =A0 =A0 =A0 =A0 =A0 =A0 I : Integer; > > =A0 =A0 =A0 =A0 =A0 =A0 B : Boolean; > > =A0 =A0 =A0 =A0 =A0 =A0 A : A_Of_F (1 .. S); > > =A0 =A0 =A0 =A0 =A0end record; > > =A0 =A0end D; > > =A0 =A0package body D is > > =A0 =A0 =A0 function Create (N : No_Of_Samples) return R is > > =A0 =A0 =A0 begin > > =A0 =A0 =A0 =A0 =A0return (S =3D> N, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0I =3D> 0, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0B =3D> False, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0A =3D> (others =3D> 0.0)); > > =A0 =A0 =A0 end Create; > > =A0 =A0 =A0 procedure Put_Line (This_R : R) is > > =A0 =A0 =A0 begin > > =A0 =A0 =A0 =A0 =A0Put_Line (Integer'Image (This_R.I)); > > =A0 =A0 =A0 =A0 =A0Put_Line (Boolean'Image (This_R.B)); > > =A0 =A0 =A0 =A0 =A0Put_Line (No_Of_Samples'Image (This_R.S)); > > =A0 =A0 =A0 =A0 =A0for I in This_R.A'Range loop > > =A0 =A0 =A0 =A0 =A0 =A0 Put_Line (Float'Image (This_R.A (I))); > > =A0 =A0 =A0 =A0 =A0end loop; > > =A0 =A0 =A0 end Put_Line; > > =A0 =A0end D; > > > =A0 =A0R_1 : D.R :=3D D.Create (1); > > =A0 =A0R_5 : D.R :=3D D.Create (5); > > begin > > =A0 =A0D.Put_Line (R_1); > > =A0 =A0D.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": > > =A0 =A0 =A0type Delay_Type (Size : Nb_Of_Samples :=3D 0) is tagged privat= e; > =A0 =A0 =A0... > private > =A0 =A0 =A0type Delay_Type (Size : Nb_Of_Samples :=3D0) is tagged record > =A0 =A0 =A0 ... > > When I compile, I have: > "discriminants of tagged type cannot have defaults" > How can I fix it ? Just remove the " :=3D 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