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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,86ec22e070e319c0 X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: How do I get this to work?? Date: 1999/01/16 Message-ID: #1/1 X-Deja-AN: 433296928 X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 References: <76s0dp$1v4$1@nntp3.uunet.ca> <76tbvv$ba5$1@nntp3.uunet.ca> <770ifd$qui$1@goblin.uunet.ca> <771bl9$sla$1@nnrp1.dejanews.com> <77b9cp$5kh$1@nnrp1.dejanews.com> X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 916487117 nnrp-01:8836 NO-IDENT pogner.demon.co.uk:158.152.70.98 Organization: At Home Newsgroups: comp.lang.ada Date: 1999-01-16T00:00:00+00:00 List-Id: warwicks@telusplanet.net (Chris Warwick) writes: > I will admit some guilt at being a "reformed" C programmer... But, what I find > odd is the concept that pointing to an object on the "stack" is poor practice. > > Even from my Ada83 days, the only "safe" way to do dynamic memory allocation > was though the use of local variables on the stack. If I understand this > concept, then the view is that it is better to point to a newly allocated > buffer, then it is to point to a procedure's local variable. Given that most > Ada compilers have no way to deallocate memory, I seem to be trading the > potential for a pointer to exist past the life of the allocated memory for a > program continously allocates memory... Most Ada compilers support Ada.Unchecked_Deallocation. Even Ada83 compilers supported Unchecked_Deallocation. Pardon me if I'm wrong, but I think what you're missing may perhaps be the concept of 'in out' (or just 'out') parameters? especially since you can use unconstrained types. procedure Foo is type Buffer_Range is range 1 .. 1024; type Buffer is array (Buffer_Range range <>) of Integer; procedure Process_Buffer (The_Buffer : in out Buffer) is begin for I in The_Buffer'Range loop The_Buffer (I) := Integer (I); -- etc end loop; end Process_Buffer; B : Buffer (20 .. 47); N : Buffer (1 .. 0); -- a zero-length instance begin Process_Buffer (B); Process_Buffer (N); end Foo;