comp.lang.ada
 help / color / mirror / Atom feed
From: emery@linus.mitre.org (David Emery)
Subject: Re: C Strings in Ada?
Date: 12 Jun 90 14:04:06 GMT	[thread overview]
Message-ID: <EMERY.90Jun12100406@aries.linus.mitre.org> (raw)
In-Reply-To: defaria@hpclapd.HP.COM's message of 11 Jun 90 22:39:00 GMT

defaria@hpclapd.hp.com writes
>My understanding is that the compiler would allocate space on the stack for
>this variable if the size of STRING_PARAM can be determined at compile time
>not at run time.  Since STRING_PARAM is being passed into my routines it is
>not  known, at compile time,  how big   the  STRING_PARAM will be (it could
>theoretically (sp?) be INTEGER'LAST bytes long!!  

There is no requirement (in Ada or any other language) that only
objects who size is static at compile-time be allocated off the stack.
The requirement, instead, is that the size of the object be STATIC at
runtime.  The size of STRING_PARAM is known when the stack frame for
the block is built.  For instance, if STRING_PARAM is 7 characters
long, then a string of length 7 is allocated off the stack.  Almost
any block-structured language can do this (including C and Pascal).
To insure that the object being declared (C_STRING) remains static, it
is declared as a constant.  

Ada provides substantial support for types and subtypes whose size is
not known until runtime.  There are some things you can't do with
them, but in general storage allocation is not a problem.  That is
because all objects in Ada are required to be constrained, either with
a fixed size, or with a maximum size.  In the case of variant records
with defaults, the maximum size is determinable based on the range of
values of the discriminant.  

There is always the problem with overflowing either stack or heap.  If
you have a string where 'LENGTH = INTEGER'LAST, I doubt that it will fit
anywhere in main memory, and you'll get STORAGE_ERROR long before you
try to append a ASCII.NUL to it and pass it to C.

				dave emery
				emery@aries.mitre.org

  reply	other threads:[~1990-06-12 14:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-06-04 22:45 C Strings in Ada? Andy DeFaria
1990-06-07 17:41 ` stt
1990-06-08 16:00 ` Andy DeFaria
1990-06-10 20:38   ` Alex Blakemore
1990-06-11 12:57     ` Allan Doyle
1990-06-11 14:59       ` David Kassover
1990-06-11 19:48         ` Allan Doyle
1990-06-11 21:01           ` David Kassover
1990-06-11 22:30           ` Mike Murphy
1990-06-13 21:20           ` Edward Falis
1990-06-11 17:53       ` David Emery
1990-06-11 19:59         ` Allan Doyle
1990-06-15  7:53   ` Jeff Bartlett
1990-06-11 22:39 ` Andy DeFaria
1990-06-12 14:04   ` David Emery [this message]
1990-06-12 18:11   ` Mike Murphy
1990-06-13 13:43 ` stt
replies disabled

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