Subject: Re: main return...
To: Not for internal consumption <>
From: David Gilbert <>
List: current-users
Date: 03/28/1996 23:43:35
John Woods sez:
-   Ty Sarna says of "void main()":
-   > Shoot, look at all the quite experienced C programmers who don't know
-   > it's not allowed!
-   Look at all the "quite experienced" C programmers who don't know that
-	   a[i] = i++;
-   is not allowed.

gw> You're kidding, right?  I was sure it wasn't _recommended_, but I
gw> didn't know it was explicitly forbidden.

	The problem here is that according to ANSI, the '++' operation
here can be done during the statement or after the statment so that
the generated code could legally do either:

a[i] = j;


a[i] = i;

	this is within the realm of implementation defined behavior, I
believe.  Notice that the pointer dereferencing can be done either
before or after i is incremented here.  The code generated is
dependant (with a good compiler) on how things fit into the scheduling
of your CPU.

	With a 68000 or even 68030 compiler, you're probably going to
get a consistent handling of this code --- not that I'm saying you
will --- it's implementation defined.  However, with Pentium or Alpha
or MIPS compilers, you might get any mix of these behavious throught
code that does these kinds of things since the optimizer is free to
reorder them.

	What's the part of the standard that talks about this?  I
don't have paragraph numbers, but the section basically states that
side effects within a expression do not have a guarenteed order of
evaluation.  Order of operations cannot guarentee this for you because
the side effects of operations have no order because the side effects
are not part of the expression.

|David Gilbert, PCI, Richmond Hill, Ontario.  | Two things can only be     |
|Mail:         |  equal if and only if they |
|               |   are precisely opposite.  |