comp.lang.ada
 help / color / mirror / Atom feed
* How do typical Ada calling conventions work ?
@ 2015-08-21  8:37 Hadrien Grasland
  2015-08-21 10:41 ` Markus Schöpflin
  2015-08-25 18:38 ` gautier_niouzes
  0 siblings, 2 replies; 11+ messages in thread
From: Hadrien Grasland @ 2015-08-21  8:37 UTC (permalink / raw)


I am currently having fun re-implementing some of Numerical Recipes' code snippets 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 suddenly found myself wondering what kind of implementation magic made my code work at all.

Let me elaborate: in the C family, as far as I know, programming language rules enforce that the size of almost any variable, including function results, 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 registers or on the stack frame, right before pushing parameters. Upon function return, 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 write 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-08-31 23:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-21  8:37 How do typical Ada calling conventions work ? Hadrien Grasland
2015-08-21 10:41 ` Markus Schöpflin
2015-08-21 12:47   ` Niklas Holsti
2015-08-22  8:31     ` Hadrien Grasland
2015-08-24 22:03       ` Randy Brukardt
2015-08-25  5:32         ` Per Sandberg
2015-08-25  7:05           ` AdaMagica
2015-08-25  7:28             ` AdaMagica
2015-08-31 23:01           ` Randy Brukardt
2015-08-25 18:38 ` gautier_niouzes
2015-08-26 15:53   ` Hadrien Grasland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox