Fred <> writes:
> On Aug 4, 10:13*am, "Bill Cunningham" <nos...@nspam.invalid> wrote:
>> * * I wrote this little reader program I like. It's just for fun anyway but
>> what does it mean that getc can be implemented as a macro and be reused
>> while fgetc can't? The only difference I see in them is the f in front. Also
>> Where I used != in my code I tried using the ! and I was given an error.
>>
>
> The standard says that getc *may* (at the implementation's
> discression)
> be implemented as a macro rather that as a function, whereas
> fgetc MUST be implemented as a function.
>
> If getc is implemented as a macro, it may reference its argument
> more than once.
Not quite. Any library function may additionally be implemented
as a macro, as long as that macro meets certain restrictions,
including that it must evaluate each of its arguments exactly once
(C99 7.1.4p1). Those restrictions are relaxed for getc, so that it
it's implemented as a macro, it may evaluate its stream argument
more than once. (The stream argument rarely has side effects, so
this doesn't create any great inconvenience for programmers, but
relaxing the requirement can make getc substantially more efficient.)
[...]
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"