This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TM4C1294NCPDT: Value of function pointer is offset +1 from function address

Part Number: TM4C1294NCPDT

Tool/software: TI C/C++ Compiler

I'm using CCS 8.2 w/TI v18.1.14.LTS. I'm making a jump table to call a specific function based on a number received in a serial message. This works sometimes but, when I change the code sometimes it won't work due to address problems.

When I try to assign a function address to a function pointer (or uint32_t) - the address stored to the function pointer (or uint32_t) is offset by +1. An example of this would be the address of the function is 0x00000AA2 but, the address stored in a variable is 0x00000AA3. See simplified code below. For now I'm just subtracting 1 from the function address but, this doesn't seem like a good solution. Does anyone have any suggestions? 

in the h file

static void foo(uint8_t *ref);

static void foo2(uint8_t *ref);

in the c file:

static void (*rx_msg_proc_func[64])(uint8_t *ref);

void foo(uint8_t *ref) { }

void foo2(uint8_t *ref) { }

void rx_msg_proc(uint8_t *msg)
{
(*rx_msg_proc_func[msg[0]])(&msg[1]);
}

void init(void)
{
rx_msg_proc_func[0] = &foo; // foo address is 0x00000AA2 and *rx_msg_proc_func[0] is 0x00000AA3
rx_msg_proc_func[1] = &foo2; // foo2 address is 0x00000AF8 and *rx_msg_proc_func[1] is 0x00000AF9
uint32_t func_addr = &foo; // func_addr is 0x00000AA3 so address is being incremented regardless of variable type
}

  • Patrick Emerick said:
    When I try to assign a function address to a function pointer (or uint32_t) - the address stored to the function pointer (or uint32_t) is offset by +1.

    The Cortex-M4F used in the TM4C1294NCPDT only supports THUMB mode.

    As explained by Pointers to functions in Thumb state it is the correct behaviour for pointers to functions in THUMB mode to have the least significant bit set.