Constant Function at a Specific Address

Sometimes functions are placed at a specific address, but the sources or information regarding them are not available. The programmer knows that the function starts at address 0x1234 and wants to call it. Without having the definition of the function, the program runs into a linker error due to the lack of the target function code. The solution is to use a constant function pointer:

  void (*const fktPtr)(void) = (void(*)(void))0x1234;
  
  
  void main(void) {
  
  
    fktPtr();
  
  
  }
  
  

This gives you efficient code and no linker errors. However, it is necessary that the function at 0x1234 really exists.

Even a better way (without the need for a function pointer):

  #define erase ((void(*)(void))(0xfc06))
  
  
  void main(void) {
  
  
    erase(); /* call function at address 0xfc06 */
  
  
  }