Nginx-环境变量

今日看nginx源码,有个environ变量,在没有赋值的情况下就用了,翻遍源码也没看到是在哪儿负的值,于是想到可能是系统中的变量,或者宏或者函数。在系统头文件中找到有关于他的信息,但是还是没有找到他的本意,于是在网上搜索

https://blog.csdn.net/tom601/article/details/70036701?utm_source=blogkpcl8 

这篇文章说明了

environ变量定义为全局变量,位于glibc源代码posix/environ.c

 

#include <unistd.h>
#include <stddef.h>

/* This must be initialized; we cannot have a weak alias into bss.  */
char **__environ = NULL;
weak_alias (__environ, environ)

/* The SVR4 ABI says `_environ' will be the name to use
   in case the user overrides the weak alias `environ'.  */
weak_alias (__environ, _environ)

继续追寻weak_alias

https://blog.csdn.net/weixin_39455835/article/details/80958105

weak-alias

是一个宏,其目的是为函数添加一个”弱”别名,与”强”符号函数名区分。
说明, 如果调用函数无对应的函数无”强”符号对应的函数,则会调用该别名对应的函数
C/C++ 函数调用是以编译后的”符号”做索引调用,详情了解 <符号表>

 


//macro weak_alias
#define weak_alias(name, aliasname) _mweak_alias(name, aliasname)
#define _weak_alias(name, aliasname) \
extern __typeof(name) aliasname __attribute__((weak, alias(#name)));
//macro weak_alias end12345

 


所谓”强”符号函数名就是,普通声明定义的函数对应的函数名 
例如:

 


//strong.c
#include <stdio.h>
void print_hello(const char *s)
{
printf("print_hello: %s\n", s);
}
//strong.c end1234567

print_hello 就是一个”强”函数符号

 

 

以下测试两种情况

 

__weak_hello 有两个”弱符号”

 

print_hello 有对应的实体函数 而 print_world 则无

 

//weak.c
#include <stdio.h>
void print_hello(const char *s) __attribute__((weak, alias("__weak_hello")));
void print_world(const char *s) __attribute__((weak, alias("__weak_hello")));
void __weak_hello(const char *)
{
printf("__weak_hello: %s\n", s);
}
//weak.c end123456789

 

//main.c
int main(void)
{
print_hello("main test print_hello");
print_world("main test print_world");
return 0;
}
//main.c end12345678


编译运行测试 
$ gcc strong.c weak.c main.c && ./a.out 
print_hello: main test print_hello 
__weak: main test print_world 
$

可见其是一个弱符号,至于源头还是没有查询得到。
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值