-- In file dim_mats.adB:
WITH Ada.Text_io ; USE Ada.Text_io ;
WITH Ada.strings.unbounded ; USE Ada.strings.unbounded ;
PACKAGE Dim_mats IS
TYPE mat3_unb_str IS ARRAY
( Natural RANGE <>, Natural RANGE <>, Natural RANGE <>)
OF Unbounded_string ;
SUBTYPE arr3_unb_str IS mat3_unb_str( 0..2, 0..11, 0..2) ;
END Dim_mats ;
-- In file procdurs.adB:
WITH Dim_mats ; USE Dim_mats ;
PROCEDURE foo IS
foo_unb_str: Unbounded_string ;
idx1_nat, idx2_nat, idx3_nat: Natural := 1 ;
BEGIN
foo_unb_str := To_unbounded_string( "foobar") ;
arr3_unb_str( idx1_nat, idx2_nat, idx3_nat) := foo_unb_str ;
-- <<<<< Unable to resolve expression
END foo ;
arr3_unb_str
is a subtype, not a variable. You can’t assign to it.
Thanks for comment.
In RM95, the search phrase “variable of subtype” appears in an obscure note at 3.5.57 under scalar types, but not about the instant unbounded_string.
Therefore I assume the legal rule that subtypes must be renamed to variable names is in the Ada folklore.
The pertinent section for your example is probably 5.2 Assignment Statements which has
assignment_statement ::= variable_ name := expression;
Notice it specifies “variable” name rather than “subtype” name. Hopefully that clears it up some!
I see.[reply requires 20 chars]
A subtype is some sort of restricted type.
The Integer
type represents all integers usable on the machine (32 or 64 bits).
The Natural
subtype is an Integer
type restricted to positive and null (0) values.
The Positive
subtype is an Integer
type restricted to only positive values.
A variable is an instanciation of a type/subtype.
My_Variable : Integer;
My_Var2 : Positive;
A variable can be assigned.
My_Variable := -10;
My_Var2 := 10;
ok ty [reply requires 20 chars]