comp.lang.ada
 help / color / mirror / Atom feed
* Strings as Parameters
@ 2004-10-04 23:11 Rick Santa-Cruz
  2004-10-05  0:20 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rick Santa-Cruz @ 2004-10-04 23:11 UTC (permalink / raw)


Hi,

I really have a super easy question:

If in a subprogram I wanna use a variable of type String then I always have 
to specify, how long this String will be... for example the following way:
procedure Main is
    S: String(1..10);
begin
...
end Main;

But if I use a String as a Parameter of a function or procedure I don't have 
to specify the range. That means I can just write a procedure like this:

procedure Test_It(S: String) is
begin
...
end Test_It;

What is the technical detail behind this? And why is such possible?

Thanks in advance,
Rick 





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

* Re: Strings as Parameters
  2004-10-04 23:11 Strings as Parameters Rick Santa-Cruz
@ 2004-10-05  0:20 ` Matthew Heaney
  2004-10-05  0:41 ` Jeffrey Carter
  2004-10-05  1:21 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 2004-10-05  0:20 UTC (permalink / raw)


"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> writes:

> But if I use a String as a Parameter of a function or procedure I don't have 
> to specify the range. That means I can just write a procedure like this:
> 
> procedure Test_It(S: String) is
> begin
> ...
> end Test_It;
> 
> What is the technical detail behind this? And why is such possible?

Because some extra information, called a "dope vector", is passed in the
call.  The dope vector describes the index values of the array object
passed as the parameter.  That's how how the called operation knows the
index constraints (and the length) of the array object.




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

* Re: Strings as Parameters
  2004-10-04 23:11 Strings as Parameters Rick Santa-Cruz
  2004-10-05  0:20 ` Matthew Heaney
@ 2004-10-05  0:41 ` Jeffrey Carter
  2004-10-05  1:21 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Carter @ 2004-10-05  0:41 UTC (permalink / raw)


Rick Santa-Cruz wrote:

> If in a subprogram I wanna use a variable of type String then I
> always have to specify, how long this String will be... for example
> the following way:

> procedure Main is
>    S: String(1..10);
> begin
>    ...
> end Main;

This is not exactly true. Every object of type String must be
constrained, but you don't always need explicit bounds.

with PragmARC.Get_Line;
procedure Martha is
    Text : String := PragmARC.Get_Line;
begin -- Martha
    ...
end Martha;

This can be very powerful in combination with block statements:

All_Input : loop
    Put (Prompt);

    One_Line : declare
       Line : String := PragmARC.Get_Line;
    begin -- One_Line
       exit All_Input when Time_To_Exit (Line);

       Process (Line);
    end One_Line;
end loop All_Input;

Every time through the loop, Line has a different value with different 
bounds.

Sometimes the block statement can be eliminated:

All_Input : loop
    Process (PragmARC.Get_Line);
end loop All_Input;

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail
18




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

* Re: Strings as Parameters
  2004-10-04 23:11 Strings as Parameters Rick Santa-Cruz
  2004-10-05  0:20 ` Matthew Heaney
  2004-10-05  0:41 ` Jeffrey Carter
@ 2004-10-05  1:21 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2004-10-05  1:21 UTC (permalink / raw)
  To: comp.lang.ada

"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> writes:

> Hi,
> 
> I really have a super easy question:
> 
> If in a subprogram I wanna use a variable of type String then I always have 
> to specify, how long this String will be... for example the following way:
> procedure Main is
>     S: String(1..10);
> begin
> ...
> end Main;
> 
> But if I use a String as a Parameter of a function or procedure I don't have 
> to specify the range. That means I can just write a procedure like this:
> 
> procedure Test_It(S: String) is
> begin
> ...
> end Test_It;
> 
> What is the technical detail behind this? 

It's an example of an unconstrained array. The bounds of the array
('first and 'last) are passed with the array.

> And why is such possible?

VAX/VMS did it back in the 1970's; it's not hard :).

-- 
-- Stephe




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

end of thread, other threads:[~2004-10-05  1:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-04 23:11 Strings as Parameters Rick Santa-Cruz
2004-10-05  0:20 ` Matthew Heaney
2004-10-05  0:41 ` Jeffrey Carter
2004-10-05  1:21 ` Stephen Leake

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