AnsweredAssumed Answered

KDS and Preprocessor

Question asked by Ben Griffiths on May 29, 2018
Latest reply on Jun 6, 2018 by ZhangJennie

I'm having a problem with KDS and the pre-processor, I'm not sure if it's me mis-understanding the pre-proxcessor or a bug in the pre-processor

 

I have the following defines:

#define TIME_ON_POWER   20 // Value is in seconds

#define US_PER_S    (US_PER_MS * MS_PER_S)

#define S_TO_US(s)        (US_PER_S * s)

 

They're used in a function such as

uint32_t variable = S_TO_US( 60 - TIME_ON_POWER );

 

In my mind that should evaluate to 40,000,000 however when I look at it via the debugger it evalutles as 59,999,980

 

To solve this I just put an extra pair of brackets around 60 - TIME_ON_POWER, this means

uint32_t variable = S_TO_US( (60 - TIME_ON_POWER) );

evaulautes to 40,000,000.

 

Is this a problem with the KDS pre-processor or is my thinking/understanding flawed?

Outcomes