For an embedded device, I have file containing an array with function pointers storing interrupt handlers, define like that (I can't modify it):
typedef void (*const ISRFunction)(void);
__attribute__((weak)) void ISR0(void){ for(;;); }
__attribute__((weak)) void ISR1(void){ for(;;); }
...
__attribute__((weak)) void ISR78(void){ for(;;); }
...
ISRFunction __vector_table[0x79] =
{
(ISRFunction)&ISR0,
(ISRFunction)&ISR1,
...
(ISRFunction)&ISR78,
...
}
I have a second file which defines some functions, which I can't modify. This file is like:
void blinkLed(void)
{ ... }
Finally, I have a main source file, with main
function and configuration of device. On interrupt 78, I would like to blink led. So I write a strong function ISR78
like that:
void ISR78(void)
{
blinkLed();
}
I wondered if there was a solution to override weak function ISR78
directly by blinkLed
, ie storing address of blinkLed
inside __vector_table
without modifying it or rename function?
EDIT:
I actually use GNU gcc 4.9.3 and associated linker (GNU ld 2.24.0). I can modify main.c
and Makefile associated to project.
void func(void)
(no arguments) andvoid func()
(unspecfied number of arguments) are different types. Usevoid
always for functions without arguments to avoid problems. – Shaerweak
is designed to allow to "override" function, isn't it? So you can define/implement your same_name_function to override theweak
one. – Warrweak
function with a same_name_function use as a wrapper to function doing real job. I wonder a method to directly overrideweak
function with function doing real job – Gabriel