2013-04-23 58 views
2

我提到两个可靠来源的信息,都似乎有同样的事情,不同的定义:是的getchar()和的putchar()函数或宏?

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

+1

实现定义! – 2013-04-23 09:26:34

回答

6

getcharputchar是函数,但可以另外被定义为宏。无论它们是否取决于实施。关于标准库函数(C99,[email protected])的C标准:

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

1

有关信息,在我的Mac“人的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). 
+0

Mac OS版本10.8.3 – ElSinus 2013-04-23 09:37:59

0

这完全取决于它如何在你的编译器实现的。