3

我参考了两个可靠的信息来源,两者似乎对同一事物有不同的定义:

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()是一个宏。哪个是对的?

4

3 回答 3

6

getcharputchar是函数,但可以另外定义为宏。它们是否存在取决于实现。C 标准说关于标准库函数(C99,7.1.4@1):

头文件中声明的任何函数都可以另外实现为头文件中定义的类函数宏。

于 2013-04-23T09:35:25.737 回答
1

有关信息,在我的 mac 'man getchar' 上给出了这个:

 The fgetc() function obtains the next input character (if present) from the stream pointed at by stream, or the
 next character pushed back on the stream via ungetc(3).

 The getc() function acts essentially identically to fgetc(), but is a macro that expands in-line.

 The getchar() function is equivalent to getc(stdin).
于 2013-04-23T09:31:44.747 回答
0

这完全取决于它在编译器中的实现方式。

于 2013-04-23T09:33:59.183 回答