0

I have a header file (sample.h) for my c file (sample.c). When I prototyped a function in my header file as below.

return_type sample_fun (FILE *filePtr);

I get a compilation error saying, Syntax error: possible missing ')' or ','? When I include the stdio.h error is resolved. Is the stdio.h include mandatory? Some of my files work well without the include.

I use gcc on AIX.

San
  • 3,933
  • 7
  • 34
  • 43

2 Answers2

5

Yes, the type FILE is defined in stdio.h; if you mention it, then you must include that file.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
2

Yes it is. FILE is typedefed from a struct iobuf on most platforms. This requires that the full definition of struct iobuf be present, even though all the interfaces use FILE *, and pointer types do not normally require full definitions prior to their use (C limitation).

See this question for more information: Forward declare FILE *

Community
  • 1
  • 1
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526