4.5 Pointers to functions in Thumb state

A Thumb function is a function that consists of Thumb code and so must run in Thumb state. Any pointer to that function must have the least significant bit set to ensure that interworking works correctly.

If you are taking the address of a function, the toolchain automatically handles this for you. If you are constructing a function pointer by casting an integer value then you need to set the least significant bit yourself, as shown in the following example.

Absolute addresses of Thumb functions

typedef int (*FN)();
myfunc() {
    FN fnptrs[] = {
        (FN)(0x8084 + 1),  // Valid Thumb address
        (FN)(0x8074)       // Invalid Thumb address
    FN* myfunctions = fnptrs;
    myfunctions[0]();    // Call OK
    myfunctions[1]();    // Call fails
Non-ConfidentialPDF file icon PDF versionARM DUI0471M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.