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 applicationsIn the first case, the value is not initialized by the compiler; the value must be set by othermeans. The typical use is for configurations where the values are loaded to ROMseparately, or for special function registers that are read-only.The following examples show incorrect usage:int delta @ 0x0206; /* Error, neither *//* "__no_init" nor "const".*/__no_init int epsilon @ 0x0207; /* Error, misaligned. */DATA AND FUNCTION PLACEMENT IN SEGMENTSThe @ operator, alternatively the #pragma location directive, can be used for placingindividual variables or individual functions in named segments. The named segment caneither be a predefined segment, or a user-defined segment. The variables must bedeclared either __no_init or const. If declared const, they can have initializers.<strong>C++</strong> static member variables can be placed in named segments just like any other staticvariable.If you use your own segments, in addition to the predefined segments, the segmentsmust also be defined in the linker command file using the -Z or the -P segment controldirectives.Note: Take care when explicitly placing a variable or function in a predefined segmentother than the one used by default. This is useful in some situations, but incorrectplacement can result in anything from error messages during compilation and linking toa malfunctioning application. Carefully consider the circumstances; there might be strictrequirements on the declaration and use of the function or variable.For more information about segments, see the chapter Segment <strong>reference</strong>.Examples of placing variables in named segmentsIn the following three examples, a data object is placed in a user-defined segment. Thesegment will be allocated in default memory depending on the used data model.__no_init int alpha @ "NOINIT"; /* OK */#pragma location="CONSTANTS"const int beta; /* OK */const int gamma @ "CONSTANTS" = 3; /* OK */To override the default segment allocation, you can explicitly specify a memory attributeother than the default:__data20 __no_init int alpha @ "NOINIT";/* Placed in data20*/Part 1. Using the compiler119

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

Saved successfully!

Ooh no, something went wrong!