11.07.2015 Views

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Efficient coding for embedded applications●Avoid using inline assembler. Instead, try writing the code in C or <strong>C++</strong>, use intrinsicfunctions, or write a separate module in assembler language. For more details, seeMixing C and assembler, page 83.SAVING STACK SPACE AND RAM MEMORYThe following is a list of programming techniques that will, when followed, savememory and stack space:●●●If stack space is limited, avoid long call chains and recursive functions.Avoid using large non-scalar types, such as structures, as parameters or return type;in order to save stack space, you should instead pass them as pointers or, in <strong>C++</strong>, as<strong>reference</strong>s.Use the --reduced_stack_space option. This will eliminate holes in the stackresulting from normal optimizations.FUNCTION PROTOTYPESIt is possible to declare and define functions using one of two different styles:●Prototyped● Kernighan & Ritchie C (K&R C)Both styles are included in the C standard; however, it is recommended to use theprototyped style, since it makes it easier for the compiler to find problems in the code.In addition, using the prototyped style will make it possible to generate more efficientcode, since type promotion (implicit casting) is not needed. The K&R style is onlysupported for compatibility reasons.To make the compiler verify that all functions have proper prototypes, use the compileroption Require prototypes (--require_prototypes).Prototyped styleIn prototyped function declarations, the type for each parameter must be specified.int test(char, int); /* declaration */int test(char a, int b) /* definition */{.....}Kernighan & Ritchie styleIn K&R style—traditional pre-ISO/ANSI C—it is not possible to declare a functionprototyped. Instead, an empty parameter list is used in the function declaration. Also,the definition looks different.Part 1. Using the compiler125

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!