Constant Function at Specific Address

Sometimes functions are placed at a specific address, but the information regarding the functions is not available. The programmer knows the function starts at address 0x1234 and wants to call it. Without having the function definition, a linker error occurs because of the missing target function code. Use a constant function pointer to solve this problem:

  void (*const fktPtr)(void) = (void(*)(void))0x1234;

  void main(void) {
 
   fktPtr();
 
 }

This produces efficient code with no linker errors. However, the function at 0x1234 must really exist.

The following code shows a better solution, without the need for a function pointer:

  #define erase ((void(*)(void))(0xfc06))

  void main(void) {

    erase(); /* call function at address 0xfc06 */

  }