Way to verify consts?
Posted: Fri Feb 19, 2016 9:02 am
I'm sure I'm not alone in using equations in my code to calculate timer-related consts and I'm sure I'm also not alone in having occasionally been caught out by the calculated const exceeding the size of the variable type.
I don't know if David is still developing the IDE, but a suggestion would be that it would be nice to flag up any consts where the assigned value exceeds the type size - I'd guess this would have to be at compile time in many cases as clock definitions aren't always in the same file as the const calculation.
However, in the absence of that solution, is there any way I can write my code to flag up any potential problems?
I've tried something like this but it just flags the warning all the time, even when the two are the same:
I do tend to check everything manually, but a simple change such as adding a new timer or changing the clock speed can throw things out and means a whole lot more calculations - if you remember.
Any ideas?
I don't know if David is still developing the IDE, but a suggestion would be that it would be nice to flag up any consts where the assigned value exceeds the type size - I'd guess this would have to be at compile time in many cases as clock definitions aren't always in the same file as the const calculation.
However, in the absence of that solution, is there any way I can write my code to flag up any potential problems?
I've tried something like this but it just flags the warning all the time, even when the two are the same:
Code: Select all
Const TimerRValue as longint = 65536 - ( Fosc / PWMRate )
Const TimerReloadValue As Word = TimerRValue
#if TimerRValue <> TimerReloadValue
#warning "Timer reload inaccuracy"
#endif
Any ideas?