是否可以在全局范围内访问已在(自引用)宏中使用的变量?
我正在使用用于指代此类宏的术语。
参见 gcc.gnu.org/onlinedocs/cpp/Self-Referential-Macros.html
我的示例代码基于那里显示的示例代码。
简单示例:
#include <stdio.h>
int foo = 10; /*A variable at global scope. There may be a few of these.*/
#define foo (4 + foo) /*A self-referential macro. There may be a few of these.*/
int main()
{
printf("foo = %d\n", foo); /*Prints 14. The value after the macro expansion */
/*Is there any way to access the global variable *foo* here?*/
return 0;
}
最佳答案
是的,您可以使用#undef foo
来删除宏定义。
关于c - 如何访问被宏定义隐藏的全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51941653/