Hi all, I'm wondering if preprocessors do math or they just paste whats defined.
In this code:
I'm assuming delay(DELAY_VALUE); will compile "delay((500/5));" which means that the math is being done everytime i use DELAY_VALUE, is this the case or does the compiler figure that DELAY_VALUE never changes so it does the math and assigns it 100 instead so the math doesn't have to be done everytime it's used?
Would it instead be better to do this:
In the second example delayValue will always be 100 so there's no extra math but is that a more "optimal" way to code something like this?
For my purposes that extra math doesn't hurt at all however curiousity took over and I wanna get in the habit of coding in the most optimal way i can not just the way that works.
In this code:
Code:
#define DELAY_ITERATIONS 5
#define DELAY_VALUE (500/DELAY_ITERATIONS) // (500/5)
delay(DELAY_VALUE);
I'm assuming delay(DELAY_VALUE); will compile "delay((500/5));" which means that the math is being done everytime i use DELAY_VALUE, is this the case or does the compiler figure that DELAY_VALUE never changes so it does the math and assigns it 100 instead so the math doesn't have to be done everytime it's used?
Would it instead be better to do this:
Code:
#define DELAY_ITERATIONS 5
const uint16_t delayValue = (500/DELAY_ITERATIONS);
delay(delayValue);
In the second example delayValue will always be 100 so there's no extra math but is that a more "optimal" way to code something like this?
For my purposes that extra math doesn't hurt at all however curiousity took over and I wanna get in the habit of coding in the most optimal way i can not just the way that works.