comp.lang.ada
 help / color / mirror / Atom feed
* What's wrong with this syntax?
@ 1996-12-04  0:00 John Gluth
  1996-12-05  0:00 ` Ken Garlington
  1996-12-05  0:00 ` johnherro
  0 siblings, 2 replies; 7+ messages in thread
From: John Gluth @ 1996-12-04  0:00 UTC (permalink / raw)



Howdy,

Someone on my team asked me if I knew why Rational's Apex doesn't 
seem to like the following excerpts.  I don't see what's wrong with it
either.



Some_Limit : Constant := 1024;


for i in 1..(Some_Limit - 2) loop


It doesn't seem to want to evaluate the (Some_Limit - 2) expression.
It seems to me that Some_Limit, a named number is of type Universal
Integer.
The literal, 2, should also be of type Universal Integer.

What are we missing?


Thx,

John
jpgluth@ccgate.hac.com




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

* Re: What's wrong with this syntax?
  1996-12-04  0:00 What's wrong with this syntax? John Gluth
@ 1996-12-05  0:00 ` Ken Garlington
  1996-12-05  0:00   ` Bob Gilbert
  1996-12-05  0:00 ` johnherro
  1 sibling, 1 reply; 7+ messages in thread
From: Ken Garlington @ 1996-12-05  0:00 UTC (permalink / raw)



John Gluth wrote:
> 
> Howdy,
> 
> Someone on my team asked me if I knew why Rational's Apex doesn't
> seem to like the following excerpts.  I don't see what's wrong with it
> either.
> 
> Some_Limit : Constant := 1024;
> 
> for i in 1..(Some_Limit - 2) loop
> 
> It doesn't seem to want to evaluate the (Some_Limit - 2) expression.
> It seems to me that Some_Limit, a named number is of type Universal
> Integer.
> The literal, 2, should also be of type Universal Integer.
> 
> What are we missing?

Here's what DEC Ada V3.2-12 says about your loop:

"Type {universal_integer} is not allowed for the discrete range of a constrained
array definition, an iteration rule, or an index of an entry family [LRM 3.6.1(2)].
Default resolution to the type INTEGER does not apply because one or both expressions
is not a literal, named number, or attribute; however, the type INTEGER is assumed
[LRM 3.6.1(2)]."

Note that both references are to the Ada 83 LRM.

There are several approaches to fixing the problem; one is

"for I in Integer'(1) .. (Some_Limit - 2) loop"

Your code does compile correctly on an Ada 95 compiler (GNAT).

> 
> Thx,
> 
> John
> jpgluth@ccgate.hac.com

-- 
LMTAS - The Fighter Enterprise - "Our Brand Means Quality"
See http://www.lmtas.com for more information (job listings now available)




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

* Re: What's wrong with this syntax?
  1996-12-04  0:00 What's wrong with this syntax? John Gluth
  1996-12-05  0:00 ` Ken Garlington
@ 1996-12-05  0:00 ` johnherro
  1 sibling, 0 replies; 7+ messages in thread
From: johnherro @ 1996-12-05  0:00 UTC (permalink / raw)



John Gluth <jpgluth@ccgate.hac.com> writes:
>Some_Limit : Constant := 1024;
> ...
>for i in 1..(Some_Limit - 2) loop
>
>It doesn't seem to want to evaluate the (Some_Limit - 2) expression.

If I'm not mistaken, your code should work with Ada 95, but not with Ada
83, which doesn't allow universal integer EXPRESSIONS in ranges when the
type isn't explicitly stated.  For the same reason, in Ada 83 you can't
write for I in -1 .. 1 loop, because -1 is an expression.

Is the compiler you mentioned Ada 83?  If so, you can fix the code either
by writing
Some_Limit : constant Integer := 1024;
or by writing
for I in Integer range 1 .. (Some_Limit - 2) loop
or by writing both.  I  hope this helps.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




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

* Re: What's wrong with this syntax?
  1996-12-05  0:00 ` Ken Garlington
@ 1996-12-05  0:00   ` Bob Gilbert
  1996-12-10  0:00     ` Robert Dewar
  1996-12-15  0:00     ` Gene Ouye
  0 siblings, 2 replies; 7+ messages in thread
From: Bob Gilbert @ 1996-12-05  0:00 UTC (permalink / raw)



John Gluth wrote:
> 
> Howdy,
> 
> Someone on my team asked me if I knew why Rational's Apex doesn't
> seem to like the following excerpts.  I don't see what's wrong with it
> either.
> 
> Some_Limit : Constant := 1024;
> 
> for i in 1..(Some_Limit - 2) loop
> 
> It doesn't seem to want to evaluate the (Some_Limit - 2) expression.
> It seems to me that Some_Limit, a named number is of type Universal
> Integer.
> The literal, 2, should also be of type Universal Integer.
> 
> What are we missing?
> 

Then Ken Garlington replied:

> Here's what DEC Ada V3.2-12 says about your loop:
> 
> "Type {universal_integer} is not allowed for the discrete range of a constrained
> array definition, an iteration rule, or an index of an entry family [LRM 3.6.1(2)].
> Default resolution to the type INTEGER does not apply because one or both expressions
> is not a literal, named number, or attribute; however, the type INTEGER is assumed
> [LRM 3.6.1(2)]."
> 
> Note that both references are to the Ada 83 LRM.
> 
> There are several approaches to fixing the problem; one is
> 
> "for I in Integer'(1) .. (Some_Limit - 2) loop"
> 
> Your code does compile correctly on an Ada 95 compiler (GNAT).

The code compiled without errors using a Tartan C40 compiler (Ver 5.1).
This was true for whether the 9x options switch was off (Ada 83)
or on (some Ada 95 features available).

Curious.

-Bob

























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

* Re: What's wrong with this syntax?
  1996-12-05  0:00   ` Bob Gilbert
@ 1996-12-10  0:00     ` Robert Dewar
  1996-12-15  0:00     ` Gene Ouye
  1 sibling, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1996-12-10  0:00 UTC (permalink / raw)



Bob said

"The code compiled without errors using a Tartan C40 compiler (Ver 5.1).
This was true for whether the 9x options switch was off (Ada 83)
or on (some Ada 95 features available).

Curious.

-Bob"



Not curious, just a bug in the Tartan compiler .... I don't think any
compiler makes the claim of being 100% bug free :-)





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

* Re: What's wrong with this syntax?
  1996-12-05  0:00   ` Bob Gilbert
  1996-12-10  0:00     ` Robert Dewar
@ 1996-12-15  0:00     ` Gene Ouye
  1996-12-15  0:00       ` Matthew Heaney
  1 sibling, 1 reply; 7+ messages in thread
From: Gene Ouye @ 1996-12-15  0:00 UTC (permalink / raw)



I've been away from CLA for a while, so I don't know if this
has already been answered, but John Gluth wanted to know why:

	Some_Limit : Constant := 1024;
	...
	for i in 1..(Some_Limit - 2) loop

wouldn't compile in Rational Apex.  I'm not sure which version
of Rational Apex is being used, but it compiles fine with Apex 
version 2.2.0 in an Ada 95 view.

In an Ada 83 view, the error message is:
"(Some_Limit - 2) must be a numeric literal, named number, or 
 attribute since both bounds of its enclosing range are of type
 universal integer and a conversion to INTEGER will only take 
 place in this case [RM_83 3.6.1(2)]"

This message is almost a direct quote from the 83 LRM.  The 
"(Some_Limit - 2)" is not a numeric literal, nor is it a named 
number, nor is it an attribute.  If it were, the conversion to 
Integer would take place.  This is similar to 
"for i in -5 .. 5 loop" which is illegal because -5 is not a 
numeric literal...

In other words, it's valid Ada 95 code, and it compiles fine 
as such.  It's invalid Adaa 83 code, thus it's rejected.

Gene Ouye <geneo@rational.com>




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

* Re: What's wrong with this syntax?
  1996-12-15  0:00     ` Gene Ouye
@ 1996-12-15  0:00       ` Matthew Heaney
  0 siblings, 0 replies; 7+ messages in thread
From: Matthew Heaney @ 1996-12-15  0:00 UTC (permalink / raw)



In article <32B49811.4C8@acm.org>, geneo@acm.org wrote:

>        Some_Limit : Constant := 1024;
>        ...
>        for i in 1..(Some_Limit - 2) loop

As Robert Dewar pointed out, it's best to explicitly name the type of the
loop index if you use the loop index to dereference an array, etc

for I in Positive range 1 .. Some_Limit - 2 loop

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271




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

end of thread, other threads:[~1996-12-15  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-04  0:00 What's wrong with this syntax? John Gluth
1996-12-05  0:00 ` Ken Garlington
1996-12-05  0:00   ` Bob Gilbert
1996-12-10  0:00     ` Robert Dewar
1996-12-15  0:00     ` Gene Ouye
1996-12-15  0:00       ` Matthew Heaney
1996-12-05  0:00 ` johnherro

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