CBFalconer said:
I disagree that stdio.h is needed to use ggets. The only thing
that might cause trouble is the definition of EOF in the return
value, but detection of a negative value suffices there. So the
using program need only include things that it itself needs. If it
needs the value of EOF, or an output routine, it must include
stdio.h for its own purposes.
The following should function anywhere:
#include <stdlib.h> /* for free */
#include "ggets.h" /* for ggets */
int main(void) {
char *line;
while (0 == ggets(&line) free(line);
return 0;
}
although there may be a difficulty with the value of 'stdin', which
is hidden in the ggets macro.
I'm not sure what you mean by "although there may be a difficulty".
With a "#include <stdio.h>", there's no problem with the *value* of
stdin, because it's an undeclared identifier. Likewise for FILE.
The expansion of #include "ggets.h" refers to the identifier FILE; the
expansion of ggets(&line) refers to the identifer stdin. How exactly
do you expect the compiler to resolve these identifiers without a
"#include <stdio.h>"?
(You also have a missing right parenthesis, corrected below).
% cat tmp.c
#include <stdlib.h> /* for free */
#include "ggets.h" /* for ggets */
int main(void) {
char *line;
while (0 == ggets(&line)) free(line);
return 0;
}
% gcc -c tmp.c
In file included from tmp.c:2:
ggets.h:37: error: syntax error before 'FILE'
tmp.c: In function 'main':
tmp.c:7: error: 'stdin' undeclared (first use in this function)
tmp.c:7: error: (Each undeclared identifier is reported only once
tmp.c:7: error: for each function it appears in.)
Adding a "#include <stdio.h>" to the top of tmp.c corrects the
problem, but the #include <stdio.h>" should be in "ggets.h".