Weak函数宏定义声明

Weak函数宏定义声明 编译器为GCC

//WEAK_FUN(int, func_name, int a, int b, int c);
#define WEAK_FUN(type,name,args...) \
		type __##name(args){return 0;}\
		type name(args)__attribute__((weak, alias("__"#name)))

示例代码

//WEAK_FUN(int, func_name, int a, int b, int c);
#define WEAK_FUN(type,name,args...) type __##name(args){return 0;} type name(args)__attribute__((weak, alias("__"#name)))
WEAK_FUN(void, f1, void);
WEAK_FUN(int, f2, int a);
WEAK_FUN(int, f3, int a, char b);
WEAK_FUN(int, f4, int a, char b, short c);
int main(int argc, char **argv)
{
	f1();
	f2();
	f3();
	f4();
	return 0;
}

使用 gcc x.c -E -o x.i展开宏

void __f1(void){return 0;} void f1(void)__attribute__((weak, alias("__""f1")));
int __f2(int a){return 0;} int f2(int a)__attribute__((weak, alias("__""f2")));
int __f3(int a, char b){return 0;} int f3(int a, char b)__attribute__((weak, alias("__""f3")));
int __f4(int a, char b, short c){return 0;} int f4(int a, char b, short c)__attribute__((weak, alias("__""f4")));
int main(int argc, char **argv)
{
 f1();
 f2();
 f3();
 f4();
 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值