Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforcing C90 style declarations in gcc with -pedantic-errors #15

Open
fyquah opened this issue Mar 6, 2018 · 0 comments
Open

Enforcing C90 style declarations in gcc with -pedantic-errors #15

fyquah opened this issue Mar 6, 2018 · 0 comments

Comments

@fyquah
Copy link
Contributor

fyquah commented Mar 6, 2018

I've got asked this frequently, that I think is worth pointing out, as it might be useful for writing test cases etc.

To force gcc to throw and error with non-C89 compliant type declaration, one has to pass std=c89 and -pedantic-errors to the compiler.

$ cat main.c 
int
main()
{
  int a;
  a = 1;
  int b = 2;
  return 0;
}
$ gcc -std=c89 main.c  # succeeds
$ gcc -pedantic -std=c89 -Wall main.c
main.c:6:7: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
  int b = 2;
      ^
main.c:6:7: warning: unused variable 'b' [-Wunused-variable]
2 warnings generated.
$ gcc -pedantic-errors -std=c89  main.c
main.c:6:7: error: ISO C90 forbids mixing declarations and code [-Werror,-Wdeclaration-after-statement]
  int b = 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant