Re:Dangerous Embedded C Coding Standard Rules (2011)
by kps on Monday December 30, 2013 @12:45PM
(#6985718)
… which will (normally) only happen if the dividend is unsigned.
Another reason to prefer unsigned ints is that the C standards make signed overflow undefined. This is becoming increasingly important as code for embedded systems is built using ‘big’ optimizing compilers, rather than the simple ‘portable assemblers’ assumed by the old old rules of thumb like manually converting divides to shifts.
“If you lie to the compiler, it will get its revenge.” — Henry Spencer
Re:Dangerous Embedded C Coding Standard Rules (2011)
by nitrogen on Monday December 30, 2013 @01:05PM
(#6985852)
Another option is reciprocal multiplication, possibly with a larger integer type. Reciprocal multiplication is an important element of my software's ability to run a Kinect at ~30fps on an ARM cpu with no FPU and no division instruction.
...unless you know your compiler is capable of converting the division into cheaper operations via strength reduction, per your well-considered rule.