getch() and getche() in MSC 4.0
Guy Harris
guy at auspex.UUCP
Wed Oct 26 05:16:40 AEST 1988
>Stupid, hell. Don't you wish that every C system had some standard,
>easy way to check which "fcns" are macros?
Many of them do; it's called "the manual". For instance, from SunOS 4.0
(I suspect these items go back to the V7 documentation):
DESCRIPTION
getc() returns the next character (that is, byte) from the
named input stream, as an integer. It also moves the file
pointer, if defined, ahead one character in stream.
getchar() is defined as getc(stdin). getc and getchar are
macros.
...
BUGS
Because it is implemented as a macro, getc() treats a stream
argument with side effects incorrectly. In particular,
getc(*f++) does not work sensibly. fgetc() should be used
instead.
What do you mean by "check"? Do you mean
#if "getchar is a macro"
code that works if "getchar" is a macro...
#else
code that doesn't...
#endif
If so, try
#ifdef getchar
code that works if "getchar" is a macro...
#else
code that doesn't...
#endif
although it would be better to just write
code that works if "getchar" is a macro...
and be done with it.
>That lint warned you about such problems?
Well, yeah, it'd be nice if "lint" warned about attempts to dereference
null pointers, too, and misspellings in character strings, and....
More information about the Comp.lang.c
mailing list