A question on volatile accesses
Ron Guilmette
rfg at NCD.COM
Sun Nov 4 08:29:59 AEST 1990
Chris Torek's response to my question was (at first) incredibly confusing
to me. I see now that he (perhaps) missed the real thrust of my question,
and this was entirely my fault because I stated the question badly.
Let me restate it one more time, and I'll try to make it clear what I'm
asking about. Consider the following code:
int array[2] = { 1, 2 };
int example ()
{
volatile int *ip = &array[0];
int i;
i = *++ip;
return i;
}
My question is this. Does the ANSI standard permit the function shown
above to delay the pre-increment until *after* the pointer indirection
occurs (thus causing the function to return `1') or does the standard
*require* that the pre-increment occur *before* the pointer indirection
(thus in turn requiring the function to always return `2')?
My (naive?) assumption is that the standard requires that the pre-increment
occur *before* the resulting value is used as a basis for indirection,
but I need to know where the standard states this requirement.
The reason I need to know is as follows.
I am working with a (supposedly) ANSI C compiler which generates code for
a target instruction set which includes delayed branch instructions.
When given code like:
int array[2] = { 1, 2 };
int j = 0;
int example ()
{
volatile int *ip = &array[0];
int i;
do {
i = *++ip;
while (j);
return i;
}
The compiler generates code in which the pre-increment operation gets
stuffed into the delay slot of the (conditional) branch instruction
which is the translation of the `while' clause of the loop.
Thus, the pre-increment occurs *after* the indirection.
Thus, the function returns `1' and not `2'.
So is this a violation of the ANSI standard or what?
--
// Ron Guilmette - C++ Entomologist
// Internet: rfg at ncd.com uucp: ...uunet!lupine!rfg
// Motto: If it sticks, force it. If it breaks, it needed replacing anyway.
More information about the Comp.std.c
mailing list