|
Re: Do you use ternary operators in your code?
I really do like ternary operators, for a variety of reasons. First, I do find it easier to read in some circumstances (and it looks kinda cool), but more importantly, its useful for the macros that we use in our code. One example:
#define GetVal(leftVal, rightVal) autoSide ? leftVal : rightVal
This lets us program our autonomous modes for each side into one program. The values are different (obviously) for each side, and this saves us from having to have two entire functions for left/right (important when you are running out of space). While you can write this code into a seperate function, it's more useful as the macro (as function calls take up a considerable amount of space too).
We also use ternary ops in our Min, Max and Min/Max macros. Very handy.
A warning though: ternary operators themselves take up a lot of space in assembly, even though it's only one line of code (this makes sense). Using them too frequently can quickly run you out of space (try and use it once to set a value instead of everywhere because it's easy to write).
One weird thing that we noticed when tight on space: when the ternary op was in a function, it took up more space than when it was in a macro, but moving other small function calls (that didn't include ternarys) were actually *much* larger when in a macro. Check the map and proceed with caution.
__________________
~Alex Baxter
Programming, Arms operation, Team 254
Last edited by 10intheCrunch : 03-04-2004 at 00:31.
|