On 9/21/10 6:19 AM, Peter Stuge wrote:
Bao, Zheng wrote:
I am not quite familiar with the attribute weak. It seems to be a good way.
Normally if two functions have the same name the linker will abort with an error. If one function is weak then it will be removed, and the non-weak function will be used.
It is good and bad. It allows to override a general function easily, but on the other hand it may be difficult to determine which code is actually being used, when many functions have the same name.
If a weak function is not defined there will be no linker error... Thus, in order to give a board an easy way to define a platform specific (reboot) function in FILO, we used:
void filo_reset_handler(void) { void __attribute__((weak)) platform_reboot(void);
if (platform_reboot) platform_reboot(); else printf("Rebooting not supported.\n");
}
Stefan