??? 05/26/12 17:17 Read: times |
#187541 - Technically, they are not the same Responding to: ???'s previous message |
That is why the hex file is different.
The while(1) is known to always compare and it even makes sense in the parameters passed in to the for statement as there is nothing to compare. I'd suspect that a compare for a while(1) would be generated if the compiler did not handle this for the user, but the hex file would be seen as different. Again, the logic is technically different. The middle of the logic performs the same exact way, but the end is going to be different, regardless. if statement 1 said:
if ( a && !b && !c) is different from if statment 2 said:
if (a)
{ if b break; if c break; The logic performed seems to be the same, but again, technically, that's incorrect. The middle is definitely the same but the end logic is different. The first if statement will guarantee that all conditions are tested before moving on to some other task. Although, if the first parameter fails, one can move on. So, if you want speed, the next if statement will prioritize those compares for you and if one fails a compare jumps out of the comparison. In order to jump out of all those compares extra processes are added so that cpu time is not dedicated to comparing statements that will inherently not make a difference. Which means that you are definitely not guaranteed to test all of the parameters and hence it is not the same. So, the logic looks to be the same, but unless the logic is followed through they will be different as an example below shows. An analogy might be more helpful. If you have two fractions say, 1/4 and 25/100. Technically, one can reduce the 25/100 to 1/4, but information is then lost especially if it is part of some statistical study that had a population that was not 4. They look to be the same, but they are effectively different numbers. |