views:

51

answers:

1

Im getting this warning even though theres no possibility that it would remain uninitialized. The Visual Studio 2008 compiler fails to detect this.

How do i suppress this warning at this piece of code only?

+2  A: 

I would tend to side with the compiler on this one; you probably initialized it in a nested conditional statement which isn't always hit. But if you really insist on ignoring the warning, you can use the appropriate #pragma directive with the warning number.

Alex
Ah, thanks, although i got the code working now by altering its way of doing things.
Newbie
Anytime. For future reference: if you do something like 'int x; if (condition) x = 3; else if (anotherCondition) x = 4;' x may still be un-initialized at this point and the compiler will warn you. You could solve this by adding an 'else' catch-all, or by starting out with 'int x = 0;' or an acceptable default.
Alex
Note that - at least for simple types like int and double - the optimiser should be able to remove the unnecessary "int x = 0" step anyway if it does see all branches overwriting it, so there's very little downside (except that it's slightly misleading noise for the programmer understanding the code).
Tony