星空网 > 软件开发 > 操作系统

gcc中__builtin_return_address和__VA_ARGS__

— Built-in Function: void * __builtin_return_address (unsigned int level)

This function returns the return address of the current function, or of one of its callers. The level argument is number of frames to scan up the call stack. A value of 0 yields the return address of the current function, a value of 1 yields the return address of the caller of the current function, and so forth. When inlining the expected behavior is that the function returns the address of the function that is returned to. To work around this behavior use the noinline function attribute.

The level argument must be a constant integer.

On some machines it may be impossible to determine the return address of any function other than the current one; in such cases, or when the top of the stack has been reached, this function returns 0 or a random value. In addition, __builtin_frame_address may be used to determine if the top of the stack has been reached.

Additional post-processing of the returned value may be needed, see __builtin_extract_return_addr.

Calling this function with a nonzero argument can have unpredictable effects, including crashing the calling program. As a result, calls that are considered unsafe are diagnosed when the-Wframe-address option is in effect. Such calls should only be made in debugging situations.


 
官方文档: http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html
 
初步理解,此内建函数根据参数level返回当前函数的返回地址及当前函数调用者的返回地址,可以一直追溯到整个函数调用栈情况。
 
 
__VA_ARGS__
c99最新引入的可变参数宏,可以解决之前宏定义中没法使用可变参数的问题。
 
#define my_print1(fmt, args...)    printf(fmt, ##args)
#define my_print2(fmt, ...)          printf(fmt, ##__VA_ARGS__)
 
这两个宏定义功能一致,实现稍微有点区别。
  
 



原标题:gcc中__builtin_return_address和__VA_ARGS__

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

了解北美商标注册的最新规则:https://www.kjdsnews.com/a/1359131.html
了解北美商标注册的全部规则:https://www.kjdsnews.com/a/1359132.html
了解全球商标的概念与作用:https://www.kjdsnews.com/a/1359133.html
了解全球商标注册费用费用收取标准一览:https://www.kjdsnews.com/a/1359134.html
了解全球商标注册流程及全球注册商标网的优势:https://www.kjdsnews.com/a/1359135.html
跨境周报|TikTok面临新禁令,亚马逊卖家竞争加剧?:https://www.kjdsnews.com/a/1359136.html
淘宝给商家发了个“大红包” :https://www.kjdsnews.com/a/1836561.html
厦门曾厝垵家庭旅馆哪家最好?:https://www.vstour.cn/a/365183.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流