Re: MIT discovered issue with gcc
I want to correct a mistake I made in my last message, where my logic of
using assert() and NDEBUG was upside-down.
This doesn't affect the logic of my statement, as the use of assert()
was just an idea to let the compiler know regarding assumptions it could
make.
On 28/11/13 14:41, Octavio Alvarez wrote:
As an idea, and just thinking out loud, it could be a bad idea, how
about this:
#undef NDEBUG
int f(int a) {
assert(a == 4);
int b = a + 7;
int c = a - b + 7;
if (3/c > 4)
return 5;
return 10;
}
Note that NDEBUG is undefined, effectively not resulting in any actual
code, but the compiler could take it as an optimization hint.
I meant the other way around:
#define NDEBUG
int f(int a) {
assert(a == 4);
int b = a + 7;
int c = a - b + 7;
if (3/c > 4)
return 5;
return 10;
}
Note that NDEBUG is defined, effectively not resulting in any actual
code, but the compiler could take it as an optimization hint.
void foo(int s, int e) {
assert(s < e);
int i;
for (i = s ; i != e ; i++) {
something();
}
}
Even if NDEBUG is not defined. Or something similar, like a conditional
comment:
This, again, should have been:
#define NDEBUG
void foo(int s, int e) {
assert(s < e);
int i;
for (i = s ; i != e ; i++) {
something();
}
}
Even if NDEBUG is defined. Or something similar, like a conditional comment:
void foo(int s, int e) {
/* GCC_ASSERT(s < e) */
int i;
for (i = s ; i != e ; i++) {
something();
}
}
... or whatever hint is included.
Please excuse this mistake.
Best regards.
Reply to: