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: 103376,7aeecd1069c28415 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!feed.cgocable.net!read2.cgocable.net.POSTED!53ab2750!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Objects and the Stack? References: <32fv82F3l9al7U1@individual.net> In-Reply-To: <32fv82F3l9al7U1@individual.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sat, 18 Dec 2004 14:41:33 -0500 NNTP-Posting-Host: 24.150.168.167 X-Complaints-To: abuse@cogeco.ca X-Trace: read2.cgocable.net 1103398831 24.150.168.167 (Sat, 18 Dec 2004 14:40:31 EST) NNTP-Posting-Date: Sat, 18 Dec 2004 14:40:31 EST Organization: Cogeco Cable Xref: g2news1.google.com comp.lang.ada:7055 Date: 2004-12-18T14:41:33-05:00 List-Id: Nick Roberts wrote: > Freejack wrote: >> On Fri, 17 Dec 2004 00:28:23 +0000, Jeffrey Carter wrote: >>> The fact that pointers are generally not needed in Ada except when >>> creating things such as dynamic data structures has nothing to do >>> with tagged types. If you create objects of a classwide type, they >>> are put on the stack if you declare them there, and in a storage pool >>> if you allocate them there. ... > I suppose so, but I think I should tell you now that what you trying > (above) cannot work. The assumption in Ada is that the space reserved > within a stack frame for an object cannot be resized (even though the > space used /within/ the space reserved for an object can). So the > compiler must be able to allocate the maximum size of an object on the > stack. Since what you are attempting could cause Stack to grow to any > size without limit, the compiler cannot know what maximum to allocate. > It won't work, and so you must use the heap (or more correctly, a > 'storage pool'). > > Ada has no equivalent of alloca() in C. It might be interesting to > experiment with a compiler extension to provide this facility. Certain > algorithms might benefit from it. The difference between what alloca() gets you and what you get in the declare block is a minor difference: -- Pseudo Ada here (Ada-ised C code for alloca()) declare My_String : String_Access := Alloca(String(1..8)); begin ... Put_Line(My_String.all); -- Real Ada here declare My_String : String(1..8); begin ... Put_Line(My_String); Apart from getting a pointer from alloca(), I don't see any advantage. Both forms allocate from the stack frame. > declare > Name: String := ""; > pragma Extensible_Object(Name); > begin > ... > Name := Name & ':'; -- changes its size > ... > > It's an idea. This is taking the alloca() idea further than I think it goes. I could be wrong here, but can you realloc() an alloca() region? If so, that is something that Ada does in fact lack (including a realloc() in general, which I pine for when growing arrays). Warren.