1

I am working on a legacy C code base which includes a mix of old (K&R) style and new (ANSI) style definitions. The plan is to gradually remove all the old style definitions and replace them with new style. To help in progressing this plan, I'd like to make the compiler issue a diagnostic (warning or error) whenever an old style definition is encountered.

Using GCC, I can do this with the -Wold-style-definition option, to generate a warning whenever an old/K&R style declaration is encountered. I can also have it generate an error, using either -Werror or -Werror=old-style-definition.

However, using clang, -Wold-style-definition doesn't appear to do anything. Indeed, the Clang documentation states "This diagnostic flag exists for GCC compatibility, and has no effect in Clang."

So is there any other way to get clang to issue a diagnostic when an old style definition is encountered?

Simon Kissane
  • 4,373
  • 3
  • 34
  • 59
  • Depending on how bad the code is, `-Wmissing-prototypes` might work. Are there function declarations in prototype form present? – Lundin Mar 09 '21 at 11:10
  • All the prototypes are there already, so `-Wmissing-prototypes` doesn't complain about anything. And in fact all the prototypes are ANSI style. We'll have an ANSI style prototype for a function, but then the actual function will be declared K&R style. Obviously there has already been work to convert the code base to ANSI, it is just unfinished. – Simon Kissane Mar 09 '21 at 11:17
  • Have you tried the `-ansi` compiler option? I've never used it, so I'm not sure what it does: maybe it forces compliance with ANSI style function definitions. – Adrian Mole Mar 09 '21 at 11:25
  • @AdrianMole No, `-ansi` doesn't do that. `-ansi` is equivalent to `-std=c90` but in C90 mode clang still accepts K&R style function definitions without diagnostic. – Simon Kissane Mar 09 '21 at 18:05

0 Answers0