× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: MOVEA -> EVAL
  • From: Phil Gregory <pgregory@xxxxxxxxxxx>
  • Date: Thu, 21 Jun 2001 13:09:56 -0400

On Thu, Jun 21, 2001 at 07:39:06AM -0700, Chris Rehm wrote:
>     "Undefined operation?" Do you mean that you cannot assign values to
> array elements in such a chain in C?

Hopefully not straying too far off topic here...

C allows a single statement to modify multiple variables at once.  The
assignment chains we've been discussing are an example of this.  The C
standard does not specify the order in which the elements of such a
statement are evaluated.  Thus, a C programmer should never modify the
values of multiple variables in a single statement when some of the
variables depend on the contents of others in the statement.  The
statement

array[x] = x = 1;

is an example of this.  The element of array that is modified depends on
the value of x, which is changed in the same statement.

The C compilers I tested the code on (gcc 2.95.4 and 3.0) both modified
array[3], not array[1].  (They set the value of array[3] to 1.)  gcc 3.0
warned me: "warning: operation on `x' may be undefined".  We don't have a
C compiler on our 400, so I couldn't see what it would do.

RPG has similar limitations.  Hans gave the example of 'eval x=a+p(a);'.
The compiler may use the value of the variable a either before or after it
was modified by the function p().

>     Now, you defend the var1 = var2 = var3 ... etc. string as being "pretty
> clear." We'll forget for the moment that it is exactly that syntax I was
> using.

You were also putting in entangled variables.  If Java indeed handles such
things differently, then the discussion on them only succeeded in muddying
the waters.  I'll go through the rest of this assuming an assignment chain
of orthogonal variables.

>     I pointed out that when I have to work on code done that way, it is
> annoying and more difficult than need be. Because I need to modify a line
> of code which affects far more than my variabe, var6 in my example, I run
> the risk of making a mistake that will affect values I am not considering
> debugging. Of course I know how to work with it, but that doesn't make his
> choice any better.

Perhaps it boils down to a question of style and idiom, but (to me) the
statement

x = y = z = <some value>

indicates a stronger correlation among the variables than does

x = <some value>
y = <the same value>
z = <the same value>

I think we're just going to have to disagree on this (but I still wouldn't
mind seeing it in RPG).
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.