To suppress compiler warnings, VS2010 has compiler options and #pragma options. Compiler options affect the whole program. #pragma options can affect the whole program. #pragma options can also locally turn specific warning(s) off just before targeted code, and then turn then back on just after. #pragma warning disable 0642
will hide this warning. #pragma warning restore 0642
will restore it. This is just ugly. Other IDEs that I have seen allow single-line overrides of warnings (specific text in a comment immediately after the provoking code), but VS2010 seems not to have done this. (I could be wrong. Anyone know?)
The only fix is worse than your "problem". Local #pragma directives will make your code uglier than it is, while removing the warning. Ultimately you are better off doing what the smart people suggested. (They sometimes miss the boat.) Getting your way is not necessarily winning. You have to admit that possibility in order to deserve answers on how to do it regardless of whether it is an improvement.
Basically this question is a PREFERENCE thing. You should have said that from the get-go, by showing (with code) what you are talking about, instead of abusing helpful people by making them guess and guess again.
The compiler warning suggests that you probably should NOT write this:
if (expression)
; // Do nothing, because blah blah blah.
else
{
code that;
does something;
}
, but instead pick one of:
if (expression)
{
// Do nothing, because blah blah blah.
}
else
{
code that;
does something;
}
or
if (expression)
{ } // Do nothing, because blah blah blah.
else
{
code that;
does something;
}
You DID NOT "specifically mention this" (someone else's rewrite of code you never provided) "as a possible solution ...". Also you did not say whether you reject Riad's change of ;
to { ... }
or his surrounding #pragmas (which, by the way, are only necessary if you do NOT change ;
to { ... }
).
IN NO WAY do these variations amount to "restructur[ing] the whole if [statement] around [removing] this [warning]". (That would be if (!expression) { code that; does something; }
.)
IN NO WAY are these variations ANY "less clear" than the original.
I wouldn't mind knowing an override that isn't ugly. I might want to write something like the following, because I like to omit all those silly surrounding braces-on-empty-lines that would make sections like this twice as tall:
if (condition1)
action1;
else if (condition2)
; // (do nothing)
else if (condition3)
action3;
else if (condition4)
; // (do nothing)
else if (condition5)
action5;
else
action99;
Apparently I have to use one of the uglier options to avoid those annoying "Possible mistaken empty statement" warnings.