Quote:
|
Originally Posted by KenWittlief
it is concise in C - but unless the CPU has a HW multiplyer then multiplyer that one line of code might compile into something that will take hundreds of machine cycles to execute in assembler
when you only need an '=' getting clever to make your C look concise is usually a big mistake.
|
Actually both routines, Anthony Kesich's one-liner and Xufer's selection structure, take exactly 22 bytes of program space, just check the list file (FrcCode.lst) after compiling both. Xufers routine was the most program space efficient of the selection structures I saw because it involved the least branching (i.e. no else to set neutral which only takes 2 bytes). Anthony’s routine could probably be optimized in assembler since only the sign bit and least significant bit of one of the factors is relevant (I don't program in assembler so I am not sure). One-liners are much better for relays because it is simply addition no multiplication.
Processor speed is a different story and depends on the processor architecture.