From: eachus@mitre-bedford.arpa (Robert I. Eachus)
Subject: Re: Is this legal ?
Date: 9 Nov 91 03:20:55 GMT [thread overview]
Message-ID: <EACHUS.91Nov8192055@Dr_No.mitre.org> (raw)
In article <1991Nov08.205832.26958@convex.com> pelakh@convex.com (Boris Pelakh)
writes:
The following procedure produces a warning at compile time saying that
the declaration of NULL_LINE is exceeding the storage limit of the
implementation. At runtime, I get a storage error. It looks like the
unconstrined declare is causing an attempt to allocate a STRING(1..MAX_INT),
even though I would expect it to only declare a STRING(1..10). The RM
does not explain this particular case. Any ideas ?
Why would you expect it to allocate space for only 10 characters?
The object NULL_LINE can be used to store a STRING value of any size,
since the discriminant has a default and is of type INTEGER. There
are two standard implementations of such records, the `hidden pointer'
version which stores the actual values on the heap, and an allocate
the maximum strategy. (Some compilers implement both, with a size at
which they cut over.)
If you want to store reasonable length lines in a portable way,
try:
procedure NOT_BROKE is
subtype LINE_LENGTH is INTEGER range 0..1024;
type VAR_LINE(LENGTH : LINE_LENGTH := 10) is
record
IMAGE : STRING(1..LENGTH);
end record;
NULL_LINE : VAR_LINE;
begin
null;
end BROKE;
--
Robert I. Eachus
with STANDARD_DISCLAIMER;
use STANDARD_DISCLAIMER;
function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...
next reply other threads:[~1991-11-09 3:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-11-09 3:20 Robert I. Eachus [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-10-16 19:00 Is this legal? Simon Belmont
2021-10-17 8:35 ` Gautier write-only address
2021-10-17 8:41 ` AdaMagica
2021-10-17 18:31 ` Simon Belmont
2021-10-18 10:50 ` AdaMagica
2021-10-19 3:50 ` Randy Brukardt
1991-11-09 18:02 Is this legal ? Bud Bach
1991-11-08 20:58 Boris Pelakh
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox