This question is not bound to any specific compiler warning, the following is just an example.
Currently when I want a loop that checks an exit condition inside:
while( true ) {
doSomething();
if( condition() ) {
break;
}
doSomethingElse();
}
I can't just write that in Visual C++ - it will emit a C4127 conditional expression is constant
warning. The compiler will wave it in my face although it's quite obvious that while(true)
can't have been written accidentially.
Suppose I want code that compiles without warnings. There're workarounds at my service.
Workaround one is to use for(;;)
but it feels stupid - why would I want that weird thing instead of concise elegant idiomatic while(true)
? Workaround two is to use #pragma warning( suppress)
before while( true )
line but it adds a huge banner that is twice as big as the while
-statement itself. Workaround three is to disable C4127 for the entire project (I've seen it done in a real project) but then all possible useful instances of C4127 are also disabled.
Is there any elegant way to get rid of a pointless warning?