|
-----Original Message-----On
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
Behalf Of Mark S. Waterburyhttp://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/books
Sent: Thursday, January 29, 2009 3:19 PM
To: RPG programming on the IBM i / System i
Subject: Re: FOR loop limit
Hi, Rory:
Thanks for that link and the doc. excerpt -- I still think this is a
compiler error. The compiler should emit a compile time error,
indicating that the size of the variable is not sufficient, based on the
fact that the compiler "knows" at compile-time the upper limit, in this
case, since it was coded as a literal.
On the other hand, if you had coded:
FOR i = 1 TO x BY 1
then the compiler does not "know" what the upper limit value will be,
but some deductions can be made, e.g. based on the size of the variable
X, especially if both "i" and "x" are declared to be packed decimal.
I still think if the increment is 1, the generated code should never
cause this exception. At least, that's the semantics in most other HLLs
that I know that have a similar for-loop construct. Or, they specify
that the value of the index variable is "undefined" upon exit from the
loop. Oh, well...
Cheers,
Mark S. Waterbury
> Rory Hewitt wrote:
Not a compiler error:
c092508502.htmstart
are
The FOR operation is performed as follows:
1. If the conditioning indicators on the FOR statement line are
satisfied, the FOR operation is processed (step 2). If the indicators
not satisfied, control passes to the next operation to be processed
following the associated END or ENDFOR statement (step 8).
2. If specified, the initial value is assigned to the index name.
Otherwise, the index name retains the same value it had before the
ofindex
the loop.
3. If specified, the limit value is evaluated and compared to the
orname. If no limit value is specified, the loop repeats indefinitelyuntil it
encounters a statement that exits the loop (such as a LEAVE or GOTO)
thatthan
ends the program or procedure (such as a RETURN).
If the TO clause is specified and the index name value is greater
notthe limit value, control passes to the first statement following theENDFOR
statement. If DOWNTO is specified and the index name is less than thelimit
value, control passes to the first statement after the ENDFOR.
4. The operations in the FOR group are processed.
5. If the conditioning indicators on the END or ENDFOR statement are
orsatisfied, control passes to the statement after the associated END
itENDFOR and the loop ends.
6. If the increment value is specified, it is evaluated. Otherwise,
(stepdefaults to 1.
7. The increment value is either added to (for TO) or subtracted from
(for DOWNTO) the index name. Control passes to step 3. (Note that the
conditioning indicators on the FOR statement are not tested again
1)the
when control passes to step 3.)
8. The statement after the END or ENDFOR statement is processed when
valueconditioning indicators on the FOR, END, or ENDFOR statements are notTO) or
satisfied (step 1 or 5), or when the index value is greater than (for
less than (for DOWNTO) the limit value (step 3), or when the index
isoverflows.
"If the FOR loop is performed *n* times, the limit value is evaluated
*n+1*times and the increment value is evaluated
*n* times. This can be important if the limit value or increment value
incrementcomplex and time-consuming to evaluate, or if the limit value or
valuesvalue contains calls to subprocedures with side-effects. If multiple
evaluation of the limit or increment is not desired, calculate the
inloop."
temporaries before the FOR loop and use the temporaries in the FOR
--<mark.s.waterbury@xxxxxxx
On Thu, Jan 29, 2009 at 9:43 AM, Mark S. Waterbury
wrote:
Hi, Jeff:
IMHO, that looks like an error ("bug") in the compiler generated code
list--you should open a PMR with IBM.
What VxRyMz of i5/OS or OS/400 did you encounter this problem at? And
what did you specify for TGTRLS? (That could affect it if this problem
was already fixed in a subsequent release).
Mark S. Waterbury
This is the RPG programming on the IBM i / System i (RPG400-L) mailing
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.