1

I don't understand why following simple code is compiled (using -Wall) without even warnings by gcc and clang:

#include <stdio.h>

void foo();

int main()
{
  foo();
}

void foo(char *p)
{
    puts(p);
}

IMO this code is obviously wrong and the compiler should detect this.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • Not obviously wrong I'm afraid. `()` is not a synonym for `(void)`. Read the linked dupe for more info. – StoryTeller - Unslander Monica Feb 13 '19 at 08:32
  • 1
    @StoryTeller then it should give at least a warning for using the obsolescent declaration `void foo();` instead of `void foo(void);`, but even `-Wall -Wpedantic -Wextra -Wimplicit` won't give any warning. IMO the standard is somewhat poor concerning this. – Jabberwocky Feb 13 '19 at 08:43
  • 1
    I agree. But that's a QoI issue. I seem to recall there is a flag for warning about obsolescent features. It's not covered by `-Wall -Wextra` to avoid setting fire to entire legacy code bases. I'll see if I can dig it up. – StoryTeller - Unslander Monica Feb 13 '19 at 08:45
  • 2
    Found it. It's [`-Wstrict-prototypes`](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options). – StoryTeller - Unslander Monica Feb 13 '19 at 08:48
  • 1
    @StoryTeller just found it too myself, yes `-Wstrict-prototypes` does the job. Thanks. – Jabberwocky Feb 13 '19 at 08:50
  • There are warnings that aren't covered by `-Wpedantic`? Thank you for asking this question, I learned something useful. :) On an unrelated note, MSVC doesn't compile the code, so I guess it is not following the rules here. Or maybe there's a setting for it? – Blaze Feb 13 '19 at 08:57
  • 1
    @Blaze concerning MSVC I think it's mainly because the MS C compiler complies only poorly to the standard. – Jabberwocky Feb 13 '19 at 08:59
  • 2
    @Blaze - Strictly speaking. This isn't something for `pedantic` flags to complain about. The code is still valid according to the standard. It's just the standard that could use a fix. – StoryTeller - Unslander Monica Feb 13 '19 at 09:01

0 Answers0