如果没有找到符号的定义,连接器就会报符号未定义错误,这种被称为强引用
在处理弱引用的时候,对于未定义的弱引用,链接器不认为是一个错误,默认为 0 或者一个能够识别的特殊值
#include<stdio.h>
void test_weak_ref(void) { printf("this is a weak ref\n"); }
static void test_weakref(void) __attribute__((weakref("test_weak_ref")));
void main(void) {
printf("init done\r\n");
if (test_weakref) {
test_weakref();
} else {
printf("There is no weakref\r\n");
}
}