gpt4 book ai didi

c - getchar 是否定义为宏?

转载 作者:行者123 更新时间:2023-11-30 18:28:23 25 4
gpt4 key购买 nike

我在 K&R 第 90 页读到 getchar 通常被定义为宏。

那么,为什么这段代码实际上有效:

#include <stdio.h>

#undef getchar

int main()
{
char c;
c= getchar();
printf("%c\n",c);

return 0;
}

最佳答案

。它是一个类似宏的函数。

C99 7.1.4(P1):

Any function declared in a header may be additionally implemented as a function-like macro defined in the header,so if a library function is declared explicitly when its header is included, one of the techniques shown below can be used to ensure the declaration is not affected by such a macro.

关于c - getchar 是否定义为宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47528190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com