Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Pointer types

In this section:

The compiler has two basic types of pointers: function pointers and data pointers. Pointer types have the same alignment as the corresponding integer type.

Function pointers

The function pointers have these properties:

Execution mode

Data model

Pointer size

Address range

32-bit

n/a

32 bits

0–0xFFFF'FFFF

64-bit

ILP32

32 bits

0–0xFFFF'FFFF

64-bit

LP64

64 bits

0–0xFFFF'FFFF'FFFF'FFFF

Table 99. Function pointers 


Note

In the ILP32 data model, the representation of a pointer in a register is always 64-bit. A 32-bit pointer is zero-extended when it is loaded into a register, and a store operation only stores the lowest 32 bits.

When function pointer types are declared, attributes are inserted before the * sign, for example:

typedef void (__thumb * IntHandler) (void);

This can be rewritten using #pragma directives:

#pragma type_attribute=__thumb
typedef void IntHandler_function(void);
typedef IntHandler_function *IntHandler;

Data pointers

There is one data pointer available. It has these properties:

Execution mode

Data model

Pointer size

Address range

32-bit

n/a

32 bits

0–0xFFFF'FFFF

64-bit

ILP32

32 bits

0–0xFFFF'FFFF

64-bit

LP64

64 bits

0–0xFFFF'FFFF'FFFF'FFFF

Table 100. Data pointers 


Note

In the ILP32 data model, the representation of a pointer in a register is always 64-bit. A 32-bit pointer is zero-extended when it is loaded into a register, and a store operation only stores the lowest 32 bits.

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 pointer type to a smaller integer type is performed by truncation

  • Casting a pointer type to a larger integer type is performed by zero extension

  • 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 value of an unsigned integer type to a pointer of a larger type is performed by zero extension

size_t

size_t is the unsigned integer type of the result of the sizeof operator. In 32-bit mode and when using the ILP32 data model in 64-bit mode, the type used for size_t is unsigned int. In the LP64 data model, the type used for size_t is unsigned long.

ptrdiff_t

ptrdiff_t is the signed integer type of the result of subtracting two pointers. In 32-bit mode and when using the ILP32 data model in 64-bit mode, the type used for ptrdiff_t is the signed integer variant of the size_t type. In the LP64 data model, the type used for ptrdiff_t is signed long.

intptr_t

intptr_t is a signed integer type large enough to contain a void*. In the IAR C/C++ Compiler for Arm, the type used for intptr_t is signed long int.

uintptr_t

uintptr_t is equivalent to intptr_t, with the exception that it is unsigned.