gcc中__builtin_return_address和__VA_ARGS__

王朝学院·作者佚名  2016-05-26
窄屏简体版  字體: 小  |  中  |  大  |  超大  

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__)这两个宏定义功能一致,实现稍微有点区别。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航