You copied the Doc URL to your clipboard.

__ldrt intrinsic

The __ldrt intrinsic lets you load data from memory in your C or C++ code using an LDR{size}T instruction.


unsigned int __ldrt(const volatile void *ptr)



Points to the address of the data to be loaded from memory. To specify the size of the data to be loaded, cast the parameter to an appropriate integral type.

Table 10-10 Access widths that the __ldrt intrinsic supports

Instructiona Size of data loaded Pointer type
LDRSBT byte signed char *
LDRBT byte unsigned char *
LDRSHT halfword signed short *
LDRHT halfword unsigned short *
LDRT word int *

Return value

The __ldrt intrinsic returns the data loaded from the memory address pointed to by ptr.


The compiler does not recognize the __ldrt intrinsic when compiling for a target that does not support the LDRT instruction. The compiler generates either a warning or an error in this case, depending on the source language:

  • In C code: Warning: #223-D: function "__ldrt" declared implicitly.
  • In C++ code: Error: #20: identifier "__ldrt" is undefined.

The __ldrt intrinsic does not support access to doubleword data. The compiler generates an error if you specify an access width that is not supported.


int foo(void)
    int loc = 0xff;
    return __ldrt((const volatile int *)loc);

Compiling this code with the default options produces:

||foo|| PROC
    MOV      r1,#0xff
    LDRT     r0,[r1],#0
    BX       lr

Related reference

Related information

a If the target instruction set does not have the listed instruction, the compiler generates a sequence of instructions with equivalent behavior instead.