> The main reason for asking if A is ok, is that I'm
not 100% if A is standard accepted practice by all C++ compilers, and will not
cause trouble with some compilers.
A is allowed according to the c++03 standard, so every
compiler should support this.
> A name introduced by a declaration in a condition
(either introduced by the type-specifier-seq or the
> declarator of the condition) is in scope from its
point of declaration until the end of the substatements controlled
> by the condition. If the name is re-declared in the
outermost block of a substatement controlled by
> the condition, the declaration that re-declares the
name is ill-formed. [Example:
> if (int x = f()) {
> int x; // ill-formed, redeclaration of x
> }
> else {
> int x; // ill-formed, redeclaration of x
> }
> —end example]
> The value of a condition that is an initialized
declaration in a statement other than a switch statement is
> the value of the declared variable implicitly
converted to type bool. If that conversion is ill-formed, the
> program is ill-formed. The value of a condition that
is an initialized declaration in a switch statement is
> the value of the declared variable if it has
integral or enumeration type, or of that variable implicitly converted
> to integral or enumeration type otherwise. The value
of a condition that is an expression is the value
> of the expression, implicitly converted to bool for
statements other than switch; if that conversion is
> ill-formed, the program is ill-formed. The value of
the condition will be referred to as simply “the condition”
> where the usage is unambiguous.
But keep in mind that you may not use any additional
parentheses or logical operators.
Regards,
Markus