Use the alternate initialization sequence, Use c operators effectively – Echelon Neuron C User Manual

Page 219

Advertising
background image

Neuron C Programmer’s Guide

207

Use the Alternate Initialization Sequence

Use of the #pragma disable_mult_module_init directive saves 2 or 3 bytes of

EEPROM code space. This directive specifies to the compiler that it should
generate any required initialization code directly in the special init and event

block, rather than as a separate procedure callable from the special init and

event block.

The in-line method, which is selected as a result of use of this directive, is more

efficient in memory usage (it typically saves 3 bytes if initialization code is

present, and saves 2 bytes if no initialization code is present). However, the
drawbacks of using the directive are the following: (1) the in-line initialization

area is limited in length, and (2) there can be no linkage from the program’s
initialization code to application library or custom image initialization code (this

is typically not a problem for any Neuron 3120 Chip or 3120 Smart Transceiver).

Use C Operators Effectively

The ANSI C language has a rich set of operators. Using them effectively can
produce very efficient code.
For example, use of the C ? : operator rather than use of an if - else statement

for alternative assignments to the same left-hand-side can reduce code space,
especially if the left-hand side expression is complex.
Also, the use of multiple if - else clauses can be slightly more efficient in code

space than a switch clause. Consider the following Before-and-After example,
which saves 2 bytes of code:
Before (compiles to 40 bytes of code):

void f (unsigned c) {

switch (c) {

case

'1':

f1();
break;
case

'2':

f2();
break;
case

'3':

f3();
break;
case

'4':

f4();
break;
default:
f5();
break;
}
}

After (compiles to 38 bytes of code):

void f (unsigned c) {

if (c == '1') {

f1();

} else if (c == '2') {

f2();

Advertising