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