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!x6g2000vbg.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Allocation questions Date: Thu, 28 May 2009 03:40:10 -0700 (PDT) Organization: http://groups.google.com Message-ID: <40a2a911-6b92-407e-b1e3-deabf154892f@x6g2000vbg.googlegroups.com> References: <4a1e5d9e$0$2868$ba620e4c@news.skynet.be> <106ssailgl19b$.1sngvazrm7u5w.dlg@40tude.net> 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 1243507210 22777 127.0.0.1 (28 May 2009 10:40:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 28 May 2009 10:40:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x6g2000vbg.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:6062 Date: 2009-05-28T03:40:10-07:00 List-Id: On May 28, 11:05=A0am, "Dmitry A. Kazakov" wrote: [snip] > =A0 =A0 =A0function Create_Delay(Time_Value: Time) return Delay_T is > =A0 =A0 =A0 =A0 Result : Delay_T (Natural (Time_Value * 44_100.0)); > =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 Result.Delay_Time :=3D Time_Value; > =A0 =A0 =A0 =A0 Result.Output =A0:=3D 0.0; > =A0 =A0 =A0 =A0 return Result; > =A0 =A0 =A0end Create_Delay; It would be even better to do it all in a single assignment, so that when new components are added to the record the compiler will complain and force you to initialise them too. Cheers -- Martin 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 :=3D 0) is private; function Create (N : No_Of_Samples) return R; procedure Put_Line (This_R : R); private type R (S : No_Of_Samples :=3D 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 =3D> N, I =3D> 0, B =3D> False, A =3D> (others =3D> 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 :=3D D.Create (1); R_5 : D.R :=3D D.Create (5); begin D.Put_Line (R_1); D.Put_Line (R_5); end Demo;