Thread: onwall and such
View Single Post
  #47  
Old 05-27-2006, 02:22 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
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 --o foo.s foo.cppgcc -O0 --o foo_.-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