10

I am working on 32-bit Fedora 14 system. I'm compiling my source code using gcc.

Does anybody know how to disable warnings while compiling c code?


EDIT: Yes i know. Best thing is to fix those Warnings to avoid any undefined/unknown behavior. But currently here, i have written huge code first time and there are lots of error & warning in first compilation. Here i just want to concentrate on errors first and then i will see warnings.

10
  • 21
    The best thing for that is to fix your code so that it doesn't emit any. Commented Jul 30, 2011 at 9:43
  • 4
    when I learned programming, we were told that compiler warnings indicate severe programming errors while compiler errors often only point to missing headers, semicolons, typos and stuff. Do not disable the warnings! Fix their causes! Commented Jul 30, 2011 at 11:03
  • 3
    That's only partly correct. Some gcc warnings flag things that are best-practices as warnings and encourage you to write broken, non-portable code in their place. The best example I can think of is a braces warning for mbstate_t state = { 0 }; which encourages people to use memset(&state, 0, sizeof state); instead. The latter probably works, but it's not strictly portable. Commented Jul 30, 2011 at 15:37
  • 1
    @chux: Because the C standard requires a zero-initialized mbstate_t object, and the definition of that type is opaque. If it has any floating point or pointer members, the all-zero-bits representation need not yield the zero value that's required. Commented May 24, 2016 at 22:20
  • 3
    @chux: (mbstate_t){0} is a zero-valued mbstate_t. The result of memset is a "zero-representation". Whether it's also zero-valued is implementation-specific. An implementation may also allows mbstate_t objects that are not zero-valued to represent the initial conversion state, but that too would be implementation-specific and thus not portable, which was my whole point. Commented May 25, 2016 at 2:14

4 Answers 4

26

try to add -w option when compiling

http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

Sign up to request clarification or add additional context in comments.

3 Comments

That will disable all warnings which I don't think it's a good idea.
@celavek: neither do I. Warnings serve a purpose. To OP: Better read them and change your code accordingly to make them go away.
-w only suppress or inhibit the warning not disabling it
7

Every body tells use -Wall switch with gcc, but you want to disable it. It is not advised, Use debugger to find it.

Linus Torvalds:

"But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

4 Comments

I would not remove -Wall, but after -Wall you want to add some -Wno-* options to disable some of the nuisance and false-positive warnings.
This doesn't look like an answer to the question -- looks like an attempt to comment.
If the OP wants to disable warnings you tell him how to disable warnings. Then, if you are a nice guy you can suggest that it is not a good practice.
This doesn't try to answer the question at all... Sometimes people don't want to do things the way everyone else does them, perhaps for a reason, if you think there's an issue with how they want to do it you should leave a comment, or better yet, provide an actual solution and only then add that the solution is not advised and why.
3

let say you are getting warning -Wfoo-bar try to add compilation flag -Wno-foo-bar

Comments

2

The best is to find the problem. It will prevent you in future looking for errors, which would not have occured, if you fixed the actual one.

But, if you're sure there is no bug or you have assured the problem is caught by your code, place this somewhere in the file (where 177 the number of your warning is):

#pragma diag_suppress 177 // supress #177-D function  was declared but never referenced

2 Comments

I tried this in gcc and clang and it doesn't seem to work.
As of today, looks like it can be done with gcc's diagnostic pragmas. For example, #pragma GCC diagnostic ignored "-Wsome-error-category" to start ignoring some-error-category within the translation unit, and then #pragma GCC diagnostic pop to revert back to command-line options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.