On Sat, 2 Jun 2007, dwight elvey wrote:
> Hi Dave
Sorry - I haven't actually been following this thread ... I just happened
across the first message I responded to... and again on this one.
> I'd expect it to evaluate the left side of
the equation first before
> determining the address. A[2]=1. Any other order would not make
> sense.
Oh no - it is quite common for a compiler to evaluate the address first,
which gets stored in a holding register while the rest is evaluated ...
but this discussion is meaningless because the issue here is the occurance
of side effects. The application of side effects to multiply referenced
items within a single sequence block is not specified by the standard.
The side effect can happen as soon as the compiler emits code for the
operator in question, or it can be deferred to some later point in the
code emitted during that sequence block (and often is in the name of
optimization).
Theres also a wonderful "as if" clause which says that a compiler can
violate the standard as long as the results behave "as if" it had not
done so - An example of this might be a compiler deferring operation
from one sequence block into the next if it has
determined that doing
so will not affect the results. Since undefined operation is
by definition
undefined, the "as if" clause always applies - hence the compiler can emit
ode invoking undefined operation at the very end of our program if it
wanted (or not at all) - (one would hope that a diagnostic would also
be emitted :-) ...
It would to some compiler authors. (who sometimes
have a different
reality than you and I do)
:-)
(I'm a compiler writer)
> But that only goes to show how poor this type of
notation is for
> defining sequence of execution. This is why I still think RPN notation
> is much better for computer programming. This need not be a stack
> language like Forth. It is concise. Events happen left to right. No special
> rules. It isn't familar to what you learned in grade school but doesn't
> take long to grasp.
A long debated viewpoint - but I think a better solution would be to
emit diagnostics when such conditions are found - the problem is, although
it's simple to detect with simple variables, the use of pointers or
function calls with side-effects can make it impossible to detect such
situations. In this respect, C is like assembly - You have to know what
you are doing and avoid these traps. Perhaps the real solution is one
of education.
Any completely defined language should produce the
same results no matter
what is fed to the compilers. But, what about Y = X/0 ? In a simple
microcomputer implementation, howzbout
N = 32767; /*or 2147483647 (as used in MS-DOS file and partition size)*/
N = N + 1; ?
K&R was NOT a very rigid complete definition of the language. There were
many parts subject to choice or interpretation by the compiler author.
If you want to shoot yourself in the foot, C will provide you unlimited
large caliber ammunition.
Absolutely - even standardized C allows for may implementation dependant
aspects. This is a necessary evil due to the nature of a very widely
accomodating portable language.
Going back to the original post, . . .
in addition to real problems with compilers (such as mishandling of
scope), programmers will tend to claim bugs in the compiler whenever they
encounter different results than from their "baby duck" compiler.
Mine was FORTRAN, followed by APL, 1401 machine, 1401 SPS, BASIC, . . .
(and a real programmer can write a FORTRAN program in any language)
Without meaning to offend you, I'm going to guess that you started with
FORTH and then branched out. There does seem to be less potential for
ambiguity in a RPN language that has one operation per instruction.
(which is what makes machine language so fulfilling)
Any language of significant power allows you to hang yourself. The trick
is knowing how to handle the rope - my early computing history involved
more assembly language than anything else, and thinking from that
perspective, I have no problems understanding and avoiding these details.
It also helps that I know very precisely what code my compiler will generate
for various constructs. - and yeah, at times in "quick and dirties" I've
coded stuff invoking undefined behaviour knowing what to expect from my
own toolset (ducking).
Dave
--
dave06a (at) Dave Dunfield
dunfield (dot) Firmware development services & tools:
www.dunfield.com
com Collector of vintage computing equipment:
http://www.classiccmp.org/dunfield/index.html