'Range attribute question. 
Author Message
 'Range attribute question.


: Given the subtype declarations:

: subtype PFS_Number_Range is Positive range 1 .. Maximum_PFS_Numbers;

: subtype Possible_RP_Posns is PFS_Number_Range range 2 .. Maximum_PFS_Numbers/2;

: 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 subt
: ype

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.
--

Forgiveness for the things I do,         |
But before you come to any conclusions,  | email appreciated,
Try walking in my shoes.             DM  | arguments welcomed.



Fri, 08 Aug 1997 22:50:41 GMT  
 '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.



Sat, 09 Aug 1997 17:49:03 GMT  
 'Range attribute question.

:
: subtype Possible_RP_Posns is PFS_Number_Range range 2 .. Maximum_PFS_Numbers/2;
:
: 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

: This is probably a really dumb question given that it is now 2.45 in the
: morning here!

I guess what you meant was just

   for Current_Position in Ed_Global.Possible_RP_Posns loop ... end loop;

The 'range is just useless. Wouldn't be a good idea to go to bed
earlier ;-)
--
------------------------------------------------------------------------

Gnat Project                                    US phone: (212) 998-3489



Sun, 10 Aug 1997 04:49:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. 'range attribute and multidimensional array

2. VHDL range attribute question.

3. CW4 - Ranges question - changing range values while running

4. A question about v'range...?

5. A question about v'range...?

6. Userdefined range attribute

7. Attribute Question T'SUCC

8. How To Do Variable 'Range Limit'

9. More than one 'Range Limit Field'

10. 'jump out of range'

11. Making the attribute 'self' preferred

12. 'Pre' attribute

 

 
Powered by phpBB® Forum Software