Use neuron c extensions effectively – Echelon Neuron C User Manual
Page 220

208 Memory
Management
} else if (c == '3') {
f3();
} else if (c == '4') {
f4();
} else {
f5();
}
}
Another C language operator that can improve code efficiency is the chained
assignment. A chained assignment uses the fact that the value being assigned
can continue to be used after the assignment. The chained assignment saves
reloading or recomputing the value being assigned. Chained assignment is
shown in the following Before-and-After example.
Before (compiles to 14 bytes of code):
mtimer t1;
unsigned long int l;
void f(void) {
t1 = 5000;
l = 5000;
}
After (compiles to 13 bytes of code):
mtimer t1;
unsigned long int l;
void f(void) {
t1 = l = 5000;
}
Use of the logical operators && and || for complex conditions typically perform
faster than similar expressions that use the bit operators & and |. In addition,
use of the logical operators can make the code smaller, especially when tests for
equality or inequality with zero are part of the conditional expression. The
following Before-and-After example demonstrates this efficiency:
Before (compiles to 15 bytes of code):
void f (int a, int b, int c) {
if ((a < 0) | (b == 0) | (c > 0)) {
// take some action
}
}
After (compiles to 12 bytes of code):
void f (int a, int b, int c) {
if ((a < 0) || (b == 0) || (c > 0)) {
// take some action
}
}
Use Neuron C Extensions Effectively
The Neuron C language contains features that exist primarily to help write
efficient code.