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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.63.39 with SMTP id d7mr5772642pas.20.1440146243367; Fri, 21 Aug 2015 01:37:23 -0700 (PDT) X-Received: by 10.182.153.65 with SMTP id ve1mr99902obb.40.1440146243331; Fri, 21 Aug 2015 01:37:23 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!x6no2790193igd.0!news-out.google.com!f6ni797igi.0!nntp.google.com!se8no7532676igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 21 Aug 2015 01:37:22 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=147.173.50.100; posting-account=21X1fwoAAABfSGdxRzzAXr3Ux_KE3tHr NNTP-Posting-Host: 147.173.50.100 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2a592336-034f-4483-9aed-b5a1d997f902@googlegroups.com> Subject: How do typical Ada calling conventions work ? From: Hadrien Grasland Injection-Date: Fri, 21 Aug 2015 08:37:23 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:27545 Date: 2015-08-21T01:37:22-07:00 List-Id: I am currently having fun re-implementing some of Numerical Recipes' code s= nippets in Ada. Since this is just a personal project, I do not care about = scaling to very large matrices/vectors, so I chose to keep things simple by= allocating arrays on the stack, rather than on the heap. But then I sudden= ly found myself wondering what kind of implementation magic made my code wo= rk at all. Let me elaborate: in the C family, as far as I know, programming language r= ules enforce that the size of almost any variable, including function resul= ts, must be known at compile-time, with C99 VLAs as a notable exception. This makes it easy for implementations to devise calling conventions : the = caller can allocate as much space as needed for the return value in registe= rs or on the stack frame, right before pushing parameters. Upon function re= turn, the caller will find the result where it would expect it. However, as far as I can tell, Ada does not offer this guarantee : if I wri= te this code, for example... "type Unconstrained_Array is array (Positive range <>) of Integer; function Make_Array return Unconstrained_Array;" ...there is no way for a caller of Make_Array to tell, in advance, how big = the function's result will be. So only the callee knows enough to allocate = space for its return value. Does someone know how typical Ada implementations manage to cope with this,= and if it varies a lot from one implementation to another ? Thanks in advance, Hadrien