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.

difference between function pointer and variable pointer

hi,

  I have asked a question about the CCS memory browser.

  https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/411698

  But I found it should be a question about difference between function pointer and variable pointer.

  In TI's examples, the slope of temperature sensor is gotten by a function pointer as shown below:

//the address is 0x3D7E82

  #define getTempSlope() (*(int (*)(void))0x3D7E82)()
return ((sensorSample - getTempOffset())*(int32)getTempSlope() + FP_ROUND + KELVIN_OFF)/FP_SCALE - KELVIN;

I use a variable pointer to get the data as shown below:

//the address is 0x3D7E83
int *getTempSlope = (int*)0x3D7E83;
slope = *getTempSlope;

They can get the same slope. But be careful that they use different addresses.

Tommy told me there is something about the  op-codes but  I really don't know the reasons.

I am looking forward to your reply.

best regards.

Di

  

  

  • ok!!!!!!!!!!
    I know the truth is that I didn't read the datasheet carefully.
    The function pointer is pointed to a function!
    use the stored slope and offset calibrated per device in the factory which can be extract by a function at the following locations!!
    So there is a function called and then it return the right value...