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.

EK-TM4C123GXL: Function pointer used on TM4C

Part Number: EK-TM4C123GXL

I use a function pointer points to a function then I observe the address of the function - test and the address the function pointer - pf_test points to.

I'm confused that the second address always equals to the first address plus 1. Ex. if the first address is 0x00000298, then the second address is 0x00000299.

Everything works fine and I just want to know why these two addresses are different.

I also tried to do the same thing under CodeBlocks but it gives the same address.

int test()
{
    return 1;
}

int main()
{
    int (*pf_test)() = test;
    while(1)
    {
    }
}

  • This is the nature of the ARM Cortex M4. All functions are 16-bit aligned, but all calls to functions must be to an odd address, the address of the function + 1. The historical reason is that ARM CPUs originally supported two sets of instructions, 32-bit wide (ARM) and 16 bit wide (THUMB). You could switch between instruction sets by calling a function with an even address and it would switch to 32-bit mode, or an odd address and it would switch to 16-bit mode. With the Cortex M processors they came out with the THUMB-2 instruction set that has both 16-bit and 32-bit instructions. there is no longer a need to switch, but the use of the odd instruction address was retained.

  • Thank you for your quick reply!