initialization

while statement with initializer

允我心安 提交于 2020-08-24 10:26:04
问题 C++17 has selection statements with initializer status_code foo() { if (status_code c = bar(); c != SUCCESS) { return c; } // ... } I'd like to write a while -loop and a variable with a scope limited to the loop and initialized only once before the first iteration. // fake example, doesn't compile, is doable in many ways while (bool keep_trying = foo(); keep_trying) { // do stuff if (something) keep_trying = false; } Is there anything for this in C++17 or maybe coming in C++2a? 回答1: P0305R1,

How standard is the {0} initializer in C89?

喜欢而已 提交于 2020-08-22 03:00:21
问题 In my current project, which uses the MISRA 2004 standard, we use three GCC compilers, versions 3.2.3, 4.4.2 and 5.4.0. We run build checks with the pedantic switch and c89 standard and a load of other restrictions. One of the restrictions is that all data must be initialised at declaration. I have a problem in that on GCC 3.2.3, the universal zero initialiser {0} only compiles for arrays of the basic unitary types. If I have an array of structs, then I get a missing braces warning and the