Quote:
|
Originally Posted by ApothiX
This code (which is C),
|
It is actually C++. C does not have a bool type unless it is C99 and you include stdbool.h or something.
Quote:
|
when compiled (without optimizations) and dissassembled, produces the EXACT same assembly as this code
|
Does not!
PHP Code:
ben@oreichalkon ~ $ cat foo.cpp
#include <cstdlib>
#include <cstdio>
bool random_bool() {
return std::rand() % 2;
}
int main() {
if (random_bool()
#ifdef REDUNDANT_CHECK
== true
#endif
)
std::puts("true!");
}
ben@oreichalkon ~ $ gcc -O0 -S -o foo.s foo.cpp; gcc -O0 -S -o foo_.s -DREDUNDANT_CHECK foo.cpp
ben@oreichalkon ~ $ diff foo_.s foo.s 41,43c41,42
< movzbl %al, %eax
< cmpl $1, %eax
< jne .L3
---
> testb %al, %al
> je .L3