是getchar()和putchar()函数还是宏? [英] Are getchar() and putchar() functions or macros?
问题描述
我提到了两个可靠的信息来源,而且两者似乎对同一件事有不同的定义:
I referred to two reliable sources for the information and both seems to have different definitions of the same thing:
http://www.cplusplus.com/reference/clibr%E2% 80%A6
http://www.ocf.berkeley.edu /~pad/tigcc/doc/html/stdio_fputchar.html
第一个消息源说putchar()
是一个函数,getchar()
也是如此,但是在第二个链接中它说putchar()
是一个宏.我的书说getchar()
是宏.哪个是正确的?
The first source says putchar()
is a function, as is getchar()
, but in the second link it says putchar()
is a macro. My book says getchar()
is a macro. Which is correct?
推荐答案
getchar
和putchar
是函数,但可以另外定义为宏.它们是否存在取决于实现方式. C标准对标准库功能(C99、7.1.4 @ 1)说:
getchar
and putchar
are functions, but may additionally be defined as macros. Whether they are or not depends on the implementation. The C standard says regarding standard library functions (C99, 7.1.4@1):
标头中声明的任何函数都可以实现为标头中定义的类似函数的宏.
Any function declared in a header may be additionally implemented as a function-like macro defined in the header.
这篇关于是getchar()和putchar()函数还是宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!