Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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.

List of 33 messages in thread
TopicAuthorDate
Where can one learn Intermediate C techniques for 8051            01/01/70 00:00      
   on the right track            01/01/70 00:00      
      one more thing            01/01/70 00:00      
         Not uncommon bid bad coding standards to comply with            01/01/70 00:00      
         Not afraid of globals, but...            01/01/70 00:00      
   More keil optimizer interesting tidbits            01/01/70 00:00      
      optimization            01/01/70 00:00      
      nothing gained, nothing lost            01/01/70 00:00      
         I don't            01/01/70 00:00      
            you can do both            01/01/70 00:00      
               That is not helping the compiler            01/01/70 00:00      
                  exact same            01/01/70 00:00      
                     Technically, they are not the same            01/01/70 00:00      
                        Hmmm...            01/01/70 00:00      
                        C don't do full evaluation of logical expressions            01/01/70 00:00      
                           In discrete mathematics proving one is not a proof            01/01/70 00:00      
                              Lazy evaluation demanded            01/01/70 00:00      
                                 I have learned something new because of this            01/01/70 00:00      
                                    me too            01/01/70 00:00      
                                       Very Important            01/01/70 00:00      
                              Breaks.            01/01/70 00:00      
                                 Compile the code            01/01/70 00:00      
                                    To be more exact            01/01/70 00:00      
                                       Stop It!!            01/01/70 00:00      
                                          That is exactly what I intended            01/01/70 00:00      
                                             Switch Break.            01/01/70 00:00      
               obfusciating code to help the compiler is a VERY bad idea            01/01/70 00:00      
                  the source of this            01/01/70 00:00      
   Where can one learn Intermediate C techniques for 8051            01/01/70 00:00      
   Getting the least out of your compiler            01/01/70 00:00      
      Maybe IAR should follow their own advice?            01/01/70 00:00      
         provided the case ...            01/01/70 00:00      
            Compilers not knowing the target chip.            01/01/70 00:00      

Back to Subject List