GETC()与龟etc() - 有什么主要区别?

问题描述:

我到处都看到它几乎是相同的,或类似的东西...

Everywhere I see "it is practically identical", or something similar...

GNU C编程教程的:

有是GNU C库在另一个函数调用的函数fgetc。它是相同在大多数方面GETC,除了GETC被作为一个宏功能通常被实现和被高度优化,所以在大多数情况下preferable。 (当你从标准输入读取的情况下,GETC是一样快龟etc,因为人类慢慢键入相比,如何快速的计算机可以读取输入,但是当你从一个没有交互由人产生的流读取,龟etc可能更好。)

There is another function in the GNU C Library called fgetc. It is identical to getc in most respects, except that getc is usually implemented as a macro function and is highly optimised, so is preferable in most situations. (In situations where you are reading from standard input, getc is about as fast as fgetc, since humans type slowly compared to how fast computers can read their input, but when you are reading from a stream that is not interactively produced by a human, fgetc is probably better.)

什么其他方面的差异?我听说,他们每个人都有不同的实现(和一个可以被用作宏),但是,是什么让他们洙不同(或足够的不同),让他们在标准C库(或规格)是两者兼而有之?

What are the other differences? I have heard that they each have a different implementation (and one can be used as a macro) but, what makes them soo different (or different enough) for them to be both in the Standard C library (or specification)?

Unix环境高级编程

...

GETC 龟etc GETC 之间的区别>可
  作为宏龟etc 实施,而不能被实现为
  宏。这意味着三件事:

The difference between getc and fgetc is that getc can be implemented as a macro, whereas fgetc cannot be implemented as a macro. This means three things:


      
  • 的参数 GETC 不应该是一个前pression副作用。

  •   
  • 由于龟etc 保证是一个功能,我们可以把它的地址。这使我们能够龟etc 的地址作为参数传递
      另一个函数。

  •   
  • 拨打龟etc恐怕​​需要比调用更长的时间来 GETC ,因为它通常需要更多的时间来调用一个函数。

  •   
  • The argument to getc should not be an expression with side effects.
  • Since fgetc is guaranteed to be a function, we can take its address. This allows us to pass the address of fgetc as an argument to another function.
  • Calls to fgetc probably take longer than calls to getc, as it usually takes more time to call a function.

...