Pointer types
The compiler has two basic types of pointers: function pointers and data pointers. Pointer types have the same alignment as the corresponding integer type.
Casting
Casts between pointers have these characteristics:
Casting a value of an integer type to a pointer of a smaller type is performed by truncation
Casting a value of an integer type to a pointer of a larger type is performed by zero extension
Casting a pointer type to a smaller integer type is performed by truncation
Casting a pointer type to a larger integer type is performed by first casting the pointer to the largest pointer of the same type that fits within the integer type. After that, it is zero-extended if needed.
Casting a data pointer to a function pointer and vice versa is illegal
Casting a function pointer to an integer type gives an undefined result
Casting a
__nearpointer to a__faror a__hugepointer is performed by first zero-extending the pointer and then adding0xF0000to itCasting a
__faror a__hugepointer to a__nearpointer is an illegal operationCasting a
__near_funcpointer to a__far_funcpointer is performed by zero extensionCasting a
__far_funcpointer to a__near_funcpointer is an illegal operationCasting a
__farpointer to a__hugepointer results in the same bit patternCasting a
__hugepointer to a__farpointer is an illegal operation.
size_t
size_t is the unsigned integer type of the result of the sizeof operator. In the IAR C/C++ Compiler for RL78, the type used for size_t is unsigned int.
ptrdiff_t
ptrdiff_t is the signed integer type of the result of subtracting two pointers. In the IAR C/C++ Compiler for RL78, the type used for ptrdiff_t is the signed integer variant of the size_t type.
Note that subtracting pointers other than default pointers could result in a smaller or larger integer type. In each case, this integer type is the signed integer variant of the corresponding size_t type.
Note
It is sometimes possible to create an object that is so large that the result of subtracting two pointers in that object is negative. See this example:
char buff[60000]; /* Assuming ptrdiff_t is a 16-bit */ char *p1 = buff; /* signed integer type. */ char *p2 = buff + 60000; ptrdiff_t diff = p2 - p1; /* Result: -5536 */
intptr_t
intptr_t is a signed integer type large enough to contain a void*. In the IAR C/C++ Compiler for RL78, the type used for intptr_t is signed long.
uintptr_t
uintptr_t is equivalent to intptr_t, with the exception that it is unsigned.