getc in BSD (was FLEX issues)

Giorgos Keramidas keramida at
Tue Jul 4 00:25:45 UTC 2006

On 2006-07-03 20:06, Mike Meyer <mwm-keyword-freebsdhackers2.e313df at> wrote:
> In <44A9AC43.3090606 at>, James Bailie <jimmy at> typed:
> > Randall Hyde wrote:
> >  > This kind of gives me the impression that "getc" is defined a bit
> >  > differently under FreeBSD than other environments?  Any ideas?
> > Yes.  It's defined as a macro.
> Linux says that getc "may be implemented as a macro". Anything that
> needs a function should be using fgetc, not getc. But

The C99 standard (actually the latest public draft[1]) allows
getc() to be a macro:


|     § The getc function
|     Synopsis
|   1         #include <stdio.h>
|             int getc(FILE *stream);
|     Description
|   2 The getc function is equivalent to fgetc, except that if it is
|     implemented as a macro, it may evaluate stream more than once,
|     so the argument should never be an expression with side
|     effects.

This means one shouldn't depend on getc() being a function.

More information about the freebsd-hackers mailing list