Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
116
Feature descriptions
AVR® IAR C/C++ Compiler
Reference Guide
Templates and data memory attributes
For data memory attributes to work as expected in templates, two elements of the 
standard C++ template handling have been changed—class template partial 
specialization matching and function template parameter deduction. 
In Extended Embedded C++, the class template partial specialization matching 
algorithm works like this:
When a pointer or reference type is matched against a pointer or reference to a template 
parameter type, the template parameter type will be the type pointed to, stripped of any 
data memory attributes, if the resulting pointer or reference type is the same.
Example
// We assume that far is the memory type of the default pointer.
template<typename> class Z;
template<typename T> class Z<T *>;
Z<int _ _near *> zn;   // T = int _ _near
Z<int _ _far  *> zf;   // T = int
Z<int        *> zd;   // T = int
Z<int _ _huge *> zh;   // T = int _ _huge
In Extended Embedded C++, the function template parameter deduction algorithm 
works like this: 
When function template matching is performed and an argument is used for the 
deduction; if that argument is a pointer to a memory that can be implicitly converted to 
a default pointer, do the parameter deduction as if it was a default pointer.
When an argument is matched against a reference, do the deduction as if the argument 
and the parameter were both pointers.
Example
template<typename T> void fun(T *);
fun((int _ _near *) 0); // T = int
fun((int        *) 0); // T = int
fun((int _ _far  *) 0); // T = int
fun((int _ _huge *) 0); // T = int _ _huge
Note that line 3 above gets a different result than the analogous situation with class 
template specializations.