
'Range attribute question.
Quote:
> : Why do I get an error message for the following statement:
> : Find_First_Blank_In_Rest_Page:
> : for Current_Position in Ed_Global.Possible_RP_Posns'Range loop
> : --------------------------------------^A ###
> : --### A:error: RM 3.6.2: must denote an array object, value, or constrained subtype
> The range thingy should be preceeded by an *object* of a type, not the
> actual type itself. So if you've declared "foo" as an object of type
> Possible_RP_Posns then use:
> for Current_Position in foo'Range loop
> Should work fine.
No, that's not the problem. As the error message indicates, the prefix
of the 'Range attribute has to be an array (either an object, a value,
or a constrained subtype). Since Ed_Global.Possible_RP_Posns is a
scalar subtype, the 'Range attribute doesn't apply to it, and is in
fact unnecessary. Instead, use the subtype name itself as a range:
for Current_Position in Ed_Global.Possible_RP_Posns loop
Note that this applies to Ada 83. It's admittedly a bit confusing that
the 'First, 'Last, and 'Range attributes can be applied to arrays (where
'Range is (nearly) equivalent to 'First..'Last), but only 'First and
'Last can be applied to scalars. This may be why Ada 95 allows 'Range
for scalars -- as I just discovered a few minutes ago. (Are there any
cases in Ada 95 where Foo'Range is different from just Foo, where Foo
is scalar?)
--
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
When you're a nail, every problem looks like a hammer.