C undefined behavior fix
Quoted 8 lines
Date: Mon, 7 Jan 2002 22:49:07 +0100
From: jtv <[email protected]>
To: Bernard Dautrevaux <[email protected]>One problem I ran into considering 'char *volatile' was this one:
the compiler is supposed to disable certain optimizations involving registerization and such, but isn't it still allowed to do constant folding?
No. That would be a bug. gcc used to have volatile bugs, most of them are now gone. Please submit a bug report, if you can discover it again.
I assume you meant something like this:
char * volatile cp;
main() {
return cp - cp;
}
Quoted 8 lines · mike stump
I assume you meant something like this:
char * volatile cp;
main(){
return cp - cp;
}
No. No. In this case you're giving cp external linkage, which means it can be observed from the outside. Plus, you're reading it multiple times, which in the case of volatile definitely means it should be read multiple times because it might be modified by something external between those reads, and that may be exactly what you want to observe with your code.
What I mean (and what we're seeing in RELOC) is more like this:
char *foo() {
char * volatile cp = NULL;
return cp;
}
Jeroen