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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/27/05 07:04
Read: times


 
#95987 - preprocessor maths
Responding to: ???'s previous message
Michael Karas said:
The IAR Preprocessor is capable of parsing float type data and then converting to integer at the necessary time.

In the case of KEIL the preprocessor is only capable of working in integer (32 bit I believe).


The preprocessor has no business doing any maths at all:

K&R said:
A preprocessor performs macro substitution, conditional compilation, and inclusion of named files

No maths.

The preprocessor just generates a text file; the compiler may choose to evaluate any constant expressions at compile-time, or generate code to evaluate the expression at run-time.

Keil always evaluates constant expressions at compile-time, and does it using the normal 'C' rules for arithmetic - one of which is that everything is an int unless stated otherwise.

Therefore, the expression (12/Xtal) is evaluated as an int - and its int result is zero.
Hence, when you divide by it, you get a divide-by-zero error.

That explains why you do get the error with Keil, but not why you don't get it with IAR...

List of 31 messages in thread
TopicAuthorDate
defination under Keil            01/01/70 00:00      
   int/float            01/01/70 00:00      
   IAR PreProcessor VS Keil            01/01/70 00:00      
      confusion            01/01/70 00:00      
         just doing text subistituons I guess            01/01/70 00:00      
            un            01/01/70 00:00      
               preprocessor            01/01/70 00:00      
                  Some confusion abounds...            01/01/70 00:00      
                     Wrong again!            01/01/70 00:00      
                        Take is easy...            01/01/70 00:00      
                           The important bit...?            01/01/70 00:00      
         Floating-point not supported in eval            01/01/70 00:00      
      preprocessor maths            01/01/70 00:00      
         I was being carelessly loose............            01/01/70 00:00      
            Keil Test            01/01/70 00:00      
            Save you the trouble            01/01/70 00:00      
               Oh            01/01/70 00:00      
         preproccessor maths            01/01/70 00:00      
            ##########            01/01/70 00:00      
               thats the confusion            01/01/70 00:00      
                  In context            01/01/70 00:00      
                     Thanks            01/01/70 00:00      
                  Think about it            01/01/70 00:00      
   Aside - 'C' #define names            01/01/70 00:00      
      good coding practices            01/01/70 00:00      
   Thank you            01/01/70 00:00      
      Alternatively...            01/01/70 00:00      
         re: Alternatively...            01/01/70 00:00      
      Not a good idea            01/01/70 00:00      
         Not a good idea            01/01/70 00:00      
         floating point in ISRs            01/01/70 00:00      

Back to Subject List