It looks like this code is acceptable with gcc even though the standard states that the value of the expression is discarded in case of a void cast.
#include <iostream>
int f(int i) {
int a = i*2;
(void)a;
a++; // looks OK even after void cast
return a; // looks OK even after void cast
}
int main() {
std::cout << "f(5): " << f(5) << "\n"; // displays 11
return f(5);
}
So is it generally possible to use a change the value of a variable that has been void casted, and then what does "discarded" means in this case? Or is it a bad practice to rely on it?