cc
rbriber at POLY1.NIST.GOV
rbriber at POLY1.NIST.GOV
Sat Sep 22 06:36:30 AEST 1990
Mike Chapman writes:
I have found a peculiarity in the MIPS C compiler that is more of a
curiosity than a problem, but I wonder if someone could shed some light on
it anyway, just for fun.
Here is a sample program that exhibits the peculiar behavior:
#include <stdio.h>
int a [2];
main()
{
int i;
a[0] = 5;
a[1] = 6;
i = 0;
printf("%d %d\n", a[i++], a[i++]);
}
Depending on the order of evaluation of function arguments, I would expect
this code to generate "6 5" or "5 6". But instead it says "5 5", which
confuses me a bit. Do all pre/post increment/decrement operators only
take effect after the current source line, or what? I did check the value
of 'i' on the next line, and it was indeed 2, so that part works. For C
reference I only have the ancient K&R, which as far as I can tell does not
formally specify when these operators are supposed to do their thing. For
reference purposes, I ran this code on many platforms (6 different CPUs,
8 different compilers), and only the MIPS compiler came out with the "5 5"
answer.
(stuff deleted).
====================
Just a note that while cc gives "5 5", GNU's gcc compiler on our Iris
gives "5 6".
--
----------------------------------------------------------------------------
| Adios Amoebas, | "I've tried and I've tried and I'm still mystified, |
| Robert Briber | I can't do it anymore and I'm not satisfied." |
| 224/B210 NIST | --Elvis |
| Gaithersburg, MD |------------------------------------------------------|
| 20899 USA | rbriber at poly1.nist.gov (Internet) |
|(301) 975-6775(voice)| rbriber at enh.nist.gov (Internet) |
|(301) 975-2128 (fax) | rbriber at nbsenh (Bitnet) |
----------------------------------------------------------------------------
More information about the Comp.sys.sgi
mailing list