comp.lang.ada
 help / color / mirror / Atom feed
* Re: Is this legal ?
@ 1991-11-09  3:20 Robert I. Eachus
  0 siblings, 0 replies; 9+ messages in thread
From: Robert I. Eachus @ 1991-11-09  3:20 UTC (permalink / 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...

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Is this legal?
@ 2021-10-16 19:00 Simon Belmont
  2021-10-17  8:35 ` Gautier write-only address
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Simon Belmont @ 2021-10-16 19:00 UTC (permalink / raw)


I'm trying to learn the 2012 changes to accessibility rules, e.g. aliased parameters, additional dynamics checks, and some eliminated unnecessary typecasts.  But I am also aware of the....fluid nature of GNATs correctness of implementing them, and the following situation seems dubious.  In particular, when 'current' is an anonymous access type, it compiles without issue, but not when it's a named access type (or when explicitly converted to one).  Does anyone know off hand which is the correct behavior?

Thanks
-sb

procedure Main is

   subtype str5 is string(1..5);
   type s5_ptr is access all str5;
      
   type T is
      record
         current : access str5; 
         --current : s5_ptr; -- "aliased actual has wrong accessibility"
         foo : aliased str5;
      end record;
      
   function F (y : aliased in out str5) return access str5 is
   begin
      return y'Access;
   end F;
   
   
   procedure P (x : in out T) is
   begin
      x.current := F(x.foo);
   end P;
         
  o : T := (current => null,  foo => "Hello");
   
begin
   P(o);
end Main;

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Is this legal ?
@ 1991-11-09 18:02 Bud Bach
  0 siblings, 0 replies; 9+ messages in thread
From: Bud Bach @ 1991-11-09 18:02 UTC (permalink / raw)


pelakh@convex.com (Boris Pelakh) writes:

> Blah, Blah, Blah...

>procedure BROKE is
>   type VAR_LINE(LENGTH : INTEGER := 10) is
>      record
>             IMAGE : STRING(1..LENGTH);
>      end record;
>   NULL_LINE : VAR_LINE;
>begin
>    null;
>end BROKE;

This is sort of a FAQ.

It has been fairly common for implementations to allocate the maximum
possible space in this situation.

Is it possible that you could constrain the length to something smaller
than "Integer"?

    procedure Common_Problem is

      subtype Reasonable_Length is Integer range 1..255;

      type Var_Line (Length : Reasonable_Length := 10) is
	record
	  Image : String (1 .. Length);
	end record;

    begin
      null;
    end Common_Problem;

Of course, knowing that the compiler will allocate "Reasonable_Length"
characters for each object of type "Var_Line", you might want to choose a
different representation.  Representations for strings always seem highly
application dependent.  There has been some recent discussion about string
representations in comp.compilers that you may want to reference.

Good luck,  -- Bud



-- 
Bud Bach - Consultant				c/o Motorola
708 632-3449					Cellular Infrastructure Group
...!uunet!motcid!bachww or			1501 W. Shure Drive, MS-1235
bachww%motcid@uunet.uu.net			Arlington Heights, IL  60004

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Is this legal ?
@ 1991-11-08 20:58 Boris Pelakh
  0 siblings, 0 replies; 9+ messages in thread
From: Boris Pelakh @ 1991-11-08 20:58 UTC (permalink / raw)


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 ?

--------------

procedure BROKE is
   type VAR_LINE(LENGTH : INTEGER := 10) is
      record
             IMAGE : STRING(1..LENGTH);
      end record;
   NULL_LINE : VAR_LINE;
begin
    null;
end BROKE;

--------------

--
Boris Pelakh            Development Software Test       pelakh@convex.com
"You can see me tonight with an illegal smile. Doesn't cost very much, but
 it lasts a long while ..."		- John Prine, "Illegal Smile"

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

end of thread, other threads:[~2021-10-19  3:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-11-09  3:20 Is this legal ? Robert I. Eachus
  -- 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

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