Chris Hills said:
If in C one codes a function which includes
return a++;
does 'a' get incremented?
[...]
(For the time being I'm coding: a++; return a - 1; )
It is safe as ; constitutes a sequence point
That's true, but that wasn't OP's question.
Indirectly, it is. The increment is guaranteed to take place by
the time the sequence point is "reached". Therefore, the increment
is guaranteed to be done before the return completes.
However, if "a" were a non-static non-volatile automatic variable,
can the compiler skip the increment? I believe so, because it will
go out of scope upon executing the return, and the result is "as
if" the increment were actually done.
The OP specifically mentioned the case where ``a'' is not local to the
function.
Regardless of the standard(s) I think this is one you would need to
empirically test of the compiler(s) in question.
If this were Ada one could just refer to the standard but it's C and
nothing is guaranteed.
Huh?
The C standard defines how the return statement and the "++" operator
work. If ``return a++;'' doesn't increment ``a'' (other than in cases
covered by the as-if rule), then the compiler is broken.
The C and Ada standards are both written in English, and in fairly
similar styles. C leaves more things undefined than Ada does, but
it's reasonably clear about *what* it leaves undefined.
I believe you're missing his point. Ada has a very thorough
validation suite and stringent restrictions on what may be called
an Ada compiler. This isn't the case with C compilers; anybody
can produce what they call a C compiler. It is even possible
that there is no such thing as a fully conforming C compiler.
His point is that in the real world this is the kind of thing
that you should check whether the compiler gets it right.
Precisely
Off
hand, I would think that it is the sort of thing that a compiler
could be expected to get right but I might well be wrong.