comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: how to do things like procedure foo(A: string) is bar: string := A; begin; ...;end;
Date: Sun, 17 Dec 2017 05:25:08 -0800 (PST)
Date: 2017-12-17T05:25:08-08:00	[thread overview]
Message-ID: <99db6133-01df-4dfd-afd7-9521f937e79d@googlegroups.com> (raw)
In-Reply-To: <1e659202-ab0b-44a5-9549-3e41fa465ab4@googlegroups.com>

On Sunday, December 17, 2017 at 7:41:02 AM UTC-5, Mehdi Saada wrote:
> Fine. It means a variable's bounds must be known at initizialisation, not compilation ? I had a boggus idea of what "static" means, or when it's necessary. A boggus idea of how the whole head + stack works. I'm still not sure, but it does simplify writing things a lot.
> Thanks.

I don't write compilers, but there are different ways to attack that problem.  
My guess is that when Foo is called and has an unconstrained String type, then 
the compiler probably pushes the length of the String to the stack as well as 
the string itself (or perhaps the string object stores it for unconstrained 
strings..again...don't know the implementations used).  Then inside of Foo when 
it goes to allocate stack space, it can use those fields to calculate how much 
stack it needs for the local string vars that are initialized.  There honestly 
might be a completely different implementation (perhaps Randy or another 
compiler writer can chime in), but the point is there are ways for it to be 
done.

Now if constrained subtypes of String are used:

type Name_String is String(1..10);
procedure foo(L,R : Name_String);

Then everything can be done at compile time.

  reply	other threads:[~2017-12-17 13:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-16 20:56 how to do things like procedure foo(A: string) is bar: string := A; begin; ...;end; Mehdi Saada
2017-12-16 21:49 ` Jeffrey R. Carter
2017-12-17 12:40   ` Mehdi Saada
2017-12-17 13:25     ` Jere [this message]
2017-12-17 13:49       ` Jere
2017-12-17 13:51     ` Jeffrey R. Carter
2017-12-18 22:22     ` Randy Brukardt
2017-12-18  6:39 ` Robert Eachus
2017-12-18 15:34   ` Mehdi Saada
2017-12-18 17:31     ` Anh Vo
2017-12-18 21:14     ` Robert Eachus
2017-12-19 22:52   ` Robert Eachus
replies disabled

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