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.

Feature descriptionsTemplates and data memory attributesFor data memory attributes to work as expected in templates, two elements of thestandard <strong>C++</strong> template handling have been changed—class template partialspecialization matching and function template parameter deduction.In Extended Embedded <strong>C++</strong>, the class template partial specialization matchingalgorithm works like this:When a pointer or <strong>reference</strong> type is matched against a pointer or <strong>reference</strong> to a templateparameter type, the template parameter type will be the type pointed to, stripped of anydata memory attributes, if the resulting pointer or <strong>reference</strong> type is the same.Example// We assume that data20 is the memory type of the defaultpointer.template class Z;template class Z;Z zn;Z zf;// T = int __data16// T = intIn Extended Embedded <strong>C++</strong>, the function template parameter deduction algorithmworks like this:When function template matching is performed and an argument is used for thededuction; if that argument is a pointer to a memory that can be implicitly converted toa default pointer, do the parameter deduction as if it was a default pointer.When an argument is matched against a <strong>reference</strong>, do the deduction as if the argumentand the parameter were both pointers.Exampletemplate void fun(T *);fun((int __data16 *) 0); // T = int. The result is different// than the analogous situation with// class template specializations.fun((int *) 0); // T = intfun((int __data20 *) 0); // T = intFor templates that are matched using this modified algorithm, it is impossible to getautomatic generation of special code for pointers to small memory types. For large and“other” memory types (memory that cannot be pointed to by a default pointer) it ispossible. In order to make it possible to write templates that are fullymemory-aware—in the rare cases where this is useful—use the108<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!