Take the 2-minute tour ×

I'm getting a compile-time error. It complains that I'm initializing a variable, but not referencing it. What's happening is that I initialize it then make a debug print statement that only get's compiled in for a debug build but not a release build. The error in question is warning c4189 (it's treated as an error and won't compile).

Is it possible to suppress this warning? How about warnings in general?

share|improve this question
You shall try to understand the warning and make warning free code instead of suppressing it. –  billz Nov 1 '12 at 23:36
Why not put the variable declaration inside the debug-only part as well? –  Kerrek SB Nov 1 '12 at 23:36
If you really want to, there's a #pragma to 'fix' warnings. On the whole, though, you should fix the code, not use the #pragma. –  Jonathan Leffler Nov 1 '12 at 23:38
You can just click on the warnings tab (if you're using mvs) to hide the warnings. It should still compile. –  user1534664 Nov 1 '12 at 23:42
add comment

1 Answer

up vote 3 down vote accepted

Don't suppress the warning, fix it! Wrap the declaration and initialization of the variable so it only exists in a debug build too.

share|improve this answer
The value IS INITIALIZED but never referenced in debug since the referencing code is stripped out in a release build. –  CPlayer Nov 1 '12 at 23:38
@CPlayer you are correct, I edited my answer to give the correct solution in that case. –  Scott Chamberlain Nov 1 '12 at 23:39
add comment

Your Answer


