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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C++</strong> and memory types (<strong>MSP430</strong>X only)<strong>C++</strong> and memory types (<strong>MSP430</strong>X only)A <strong>C++</strong> class object is placed in one memory type, in the same way as for normal Cstructures. However, the class members that are considered to be part of the object arethe non-static member variables. The static member variables can be placed individuallyin any kind of memory.Remember, in <strong>C++</strong> there is only one instance of each static member variable, regardlessof the number of class objects.All restrictions that apply to the default pointer type also apply to the this pointer. Thismeans that it must be possible to convert a pointer to the object to the default pointertype. Also note that for non-static member functions—unless class memory is used, seeClasses, page 103—the this pointer will be of the default data pointer type.In the Small and Medium data models, this means that objects of classes with a memberfunction can only be placed in the default memory type (__data16).ExampleIn the example below, an object, named delta, of the type MyClass is defined in data16memory. The class contains a static member variable that is stored in data20 memory.// The class declaration (placed in a header file):class MyClass{public:int alpha;int beta;__data20 static int gamma;};// Definitions needed (should be placed in a source file):__data20 int MyClass::gamma;// A variable definition:__data16 MyClass delta;The stack and auto variablesVariables that are defined inside a function—not declared static—are named autovariables by the C standard. A small number of these variables are placed in processorregisters; the rest are placed on the stack. From a semantic point of view, this isequivalent. The main differences are that accessing registers is faster, and that lessmemory is required compared to when variables are located on the stack.20<strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong>Reference Guide

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

Saved successfully!

Ooh no, something went wrong!