Bruce
P.S. Here's the code...
#inclue <stdlib.h>
#include <setjmp.h>
static jmp_buf env;
void
SetZero(intAddr)
int* intAddr;
{
*intAddr = 0;
}
void
DeadCodeEliminationConflict(void)
{
int local = 1;
switch(setjmp(env)) {
case 0:
case 1:
printf("case 0/1...\n");
if (local) {
longjmp(env, 2);
}
break;
case 2:
printf("case 2...\n");
local = 0; /* GCC 2.5.8 thinks this is dead code */
/* SetZero(&local); Is this dead code too? */
longjmp(env, 1);
default:
printf("Unhandled case...\n");
break;
}
}
main(int argc, char** argv)
{
DeadCodeEliminationConflict();
exit(0);
}
I haven't looked at the asm output, but I don't think this is the case.
It is probably just some interaction of setjmp() and longjmp() with
variables on the stack. Declaring local as volatile works.
Stephen
>While writing some code that relies on setjmp and longjmp ...,
<stuff deleted ...>
>least, want an optimization that eliminates seemingly useless code,
> int local = 1;
^-- Maybe add the 'volatile' keyword here ? (Spell it
correctly, though)
I believe that the 'volatile' keyword is a cue to the compiler that
the variable is a sentinal of some sort, perhaps even in the case of
a pointer, mapped to a hardware register or something. At least that's
my understanding of it. If you supply that keyword, maybe the optimizer
will stop messing with it.
Curt Eckhart
cu...@bkrycft.com