G
Gianguz
The following code compiled with gcc version 3.3.4 20040623 (Gentoo
Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6) produce a segmentation fault
and has a size
of 9095 byte on my machine:
#include <iostream>
using namespace std;
const bool v = true;
void modifyConst() {
const bool tmp = v;
const_cast<bool&>(v) = !tmp;
return;
}
int main() {
do {
if (v) {
cout << "FOREVER HERE?!?!" << endl;
modifyConst();
}
else {
cout << "THIS CODE WILL NOT BE GENERATED?!" << endl;
}
}
while(v);
}
The same code with "bool v = true;" instead of "const bool v = true;"
has a size of 9184 byte and runs with no error.
Had the compiler removed the 'else branch' and the 'while cmp
instruction' only looking at the const declaration? If so, why it
can't handle the assignment (with cast) in the modifyConst? It should
be able to understand that what was previously considered a 'safe
const' (regarding to optimizations and expressions reduction) now is
no more a 'safe' one.
Thanks,
Gianguglielmo
Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6) produce a segmentation fault
and has a size
of 9095 byte on my machine:
#include <iostream>
using namespace std;
const bool v = true;
void modifyConst() {
const bool tmp = v;
const_cast<bool&>(v) = !tmp;
return;
}
int main() {
do {
if (v) {
cout << "FOREVER HERE?!?!" << endl;
modifyConst();
}
else {
cout << "THIS CODE WILL NOT BE GENERATED?!" << endl;
}
}
while(v);
}
The same code with "bool v = true;" instead of "const bool v = true;"
has a size of 9184 byte and runs with no error.
Had the compiler removed the 'else branch' and the 'while cmp
instruction' only looking at the const declaration? If so, why it
can't handle the assignment (with cast) in the modifyConst? It should
be able to understand that what was previously considered a 'safe
const' (regarding to optimizations and expressions reduction) now is
no more a 'safe' one.
Thanks,
Gianguglielmo