3

In C, function declarations can be prototype or non-prototype declarations. For example, consider the following minimal program:

int foo (); /* non-prototype declaration */

int bar (void); /* prototype declaration */

int main (int argc, char **argv)
{
  return 0;
}

Although in C99 non-prototype declarations are obsolete, I cannot get GCC to complain about them. For example, compiling the above program with GCC and all errors enabled just succeeds:

$ gcc -std=c99 -pedantic -Werror -Wall test.c
$

Is there any way to persuade GCC to emit warnings for function declarations that aren't prototypes?

(Question inspired by an answer by Keith Thompson.)

Community
  • 1
  • 1
Peter T.B. Brett
  • 1,250
  • 11
  • 20

2 Answers2

5

I think the option you are looking for is -Wstrict-prototypes

celtschk
  • 19,311
  • 3
  • 39
  • 64
2

Note that gcc with -std=c99 -pedantic -Wall options doesn't issue any warning for the old style function declarations but C doesn't require the implementation to issue a diagnostic in presence of the old style function declarations.

C characterizes the use of old style function declaration as obsolescent since C89 but it it still valid C code (in C89/C99/C11).

ouah
  • 142,963
  • 15
  • 272
  • 331