comp.lang.ada
 help / color / mirror / Atom feed
* Access to aliased string declaration question.
@ 1999-06-09  0:00 Rex Reges
  1999-06-10  0:00 ` Matthew Heaney
  1999-06-10  0:00 ` Robert Dewar
  0 siblings, 2 replies; 4+ messages in thread
From: Rex Reges @ 1999-06-09  0:00 UTC (permalink / raw)


Example program below doesn't compile...

with Text_IO ;
use  Text_IO ;

procedure Borg is

   -- Example of ragged arrays using heap and declared values.

   -- Create access to unconstrained type string.
   type String_Access_Type is access all String ;

   -- Define an array of strings:
   type String_Array_Type is array ( Positive range <> ) of
String_Access_Type ;

   -- Declare "ragged" arrays of strings...
   Borg_Strings  : String_Array_Type ( 1..3 ) ;
   Dalek_Strings : String_Array_Type ( 1..3 ) ;

   -- Create constants for alias access example.
   --                                                 
123456789112345678921
   Static_Dalek_String_1 : aliased String( 1..21 ) := "Resistance is
futile."  ;
   Static_Dalek_String_2 : aliased String( 1..12 ) :=
"Exterminate!"           ;
   Static_Dalek_String_3 : aliased String( 1..12 ) :=
"Exterminate!"           ;


begin
 
   -- Create the heap strings.
 
   Borg_Strings(1) := new String'( "We are the Borg."         );
   Borg_Strings(2) := new String'( "Resistance is futile."    );
   Borg_Strings(3) := new String'( "You will be assimilated." );
 
 
   -- Assign the declared strings.
 
   Dalek_Strings := ( 1 => Static_Dalek_String_1'access ,
                      2 => Static_Dalek_String_2'access ,
                      3 => Static_Dalek_String_3'access ) ;
 
 
   -- The Borg versus the Daleks...
   for I in 1..3 
   loop
       Put_Line( "Borg:  " & Borg_Strings ( I ).all ) ;
       Put_Line( "Dalek: " & Dalek_Strings( I ).all ) ;
   end loop ;
   
 
end Borg;

End of example program.
The compilation results for this program are:

   $ gnatmake borg.adb
   gcc -c borg.adb
   borg.adb:36:28: object subtype must statically match designated
subtype
   borg.adb:37:28: object subtype must statically match designated
subtype
   borg.adb:38:28: object subtype must statically match designated
subtype
   gnatmake: "borg.adb" compilation error


If I remove the Dalek's string range indices, the program compiles 
without error:

   Static_Dalek_String_1 : aliased String := "Resistance is futile."  ;
   Static_Dalek_String_2 : aliased String := "Exterminate!"           ;
   Static_Dalek_String_3 : aliased String := "Exterminate!"           ;


Why is this so? Shouldn't String_Access_Type be able to point to any
string?


Rex Reges




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

end of thread, other threads:[~1999-06-10  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-09  0:00 Access to aliased string declaration question Rex Reges
1999-06-10  0:00 ` Matthew Heaney
1999-06-10  0:00   ` Matthew Heaney
1999-06-10  0:00 ` Robert Dewar

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