
February 26th, 2004, 02:14 AM
|
First Lieutenant
|
|
Join Date: Dec 2003
Location: Calgary, Canada
Posts: 762
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: 2.08 and Incompatible Battle Reports
Quote:
Originally posted by Arryn:
Alexti, your examples are not the same. In the first example: 1) they have void returns and invoke I/O, which the optimizer treats differently.
|
How the optimizer would know about IO? printf is just some function residing in some library to which optimizer had no access. It only can see the header, where there's nothing that says that the function contains IO.
Quote:
2) the statements are on separate lines, and IIRC there are various scoping rules to what the compiler will attempt to "consolidate" when it goes to generate machine code.
|
Some Languages consider line feeds as a language element, but not C/C++.
code:
f(); f();
and
code:
f();
f();
are the same thing.
Quote:
However, the most obvious thing you said that bears careful review is the statement "... it's safe to assume ...". It's never safe to assume anything. That's the first step towards making mistakes ...
|
You have to assume that the compiler works correctly (according to the standard) until proven otherwise, how are going to write any code otherwise?
Consider the following:
code:
int a = 1;
foo(a);
What if the compiler generate wrong code for assignement? Ok, here is an improvement:
code:
int a = 1;
if (a != 1)
ERROR("!!!");
foo(a);
But what if the code for comparison is wrong too? No problems:
code:
int a = 1;
if (a != 1 || (a-1))
ERROR("!!!");
foo(a);
But what if operator or (||) produces wrong code too?
Well, it's clear where it's going...
|