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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/28/05 15:01
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#90544 - Clarification
Responding to: ???'s previous message
Ian Bell said:
Donald Catto said:
That particular article refers to a char being compared with an integer. There's nothing surprising about the char being promoted to an integer before comparison.

It refers to a char being compared to a constant, 0XC5 in the example, and failing the comparison because char is signed and therefore is promoted to int before the comparison. If an unsigned char had been used the comparison would have worked becuase integer promotion would not take place.

The char is not promoted because it is signed: the promotion occurs because two different types are being compared, where one of those two types cannot represent the value of the other, hence the promotion. Had the char been unsigned the comparison would have worked because 0xc5 fits into an unsigned char. The point I am trying to make is that the signedness is not the important issue.

This sort of behaviour can easily trap the inexperienced embedded C programmer which is why I prefer to code such operations in assembler.

The same applies to the inexperienced assembler programmer. In all but trivial cases you have to understand the language you are programming in and the platform you are programming on.







List of 40 messages in thread
TopicAuthorDate
8051 in C or assembly?            01/01/70 00:00      
   Probably C            01/01/70 00:00      
      Always C            01/01/70 00:00      
      Mostly 'C'            01/01/70 00:00      
      No magic wand            01/01/70 00:00      
      Assembler when?            01/01/70 00:00      
         Shared data problem??            01/01/70 00:00      
            Shared Data Problem            01/01/70 00:00      
               I see            01/01/70 00:00      
                  Sared Data            01/01/70 00:00      
                  addendum            01/01/70 00:00      
                     Shared Data            01/01/70 00:00      
               Knowledge, not language.            01/01/70 00:00      
                  Knowledge            01/01/70 00:00      
                     Knowledge            01/01/70 00:00      
                  Promotion            01/01/70 00:00      
                     Promotion            01/01/70 00:00      
                        Promotion            01/01/70 00:00      
                           Traps for the unwary            01/01/70 00:00      
                              Preaching            01/01/70 00:00      
                                 Ditto            01/01/70 00:00      
                                 red rag....            01/01/70 00:00      
                                    Bend over then...            01/01/70 00:00      
                           hauling assembler            01/01/70 00:00      
                           Clarification            01/01/70 00:00      
                           Keil Allows this to be disabled            01/01/70 00:00      
                              Know your tools            01/01/70 00:00      
                                 It means 8 bit may be 16 bits            01/01/70 00:00      
                  More knowledge!            01/01/70 00:00      
         not really            01/01/70 00:00      
   So which...            01/01/70 00:00      
      Calculations in C            01/01/70 00:00      
         ibid            01/01/70 00:00      
         Not always..            01/01/70 00:00      
            Example            01/01/70 00:00      
   Better??            01/01/70 00:00      
   assembly            01/01/70 00:00      
      YMMV            01/01/70 00:00      
   assembly            01/01/70 00:00      
      Hitting the Wall            01/01/70 00:00      

Back to Subject List