In C, it\'s legal to write something like:
int foo = +4;
However, as far as I can tell, the unary plus (+
) in +4
What is the purpose of the unary '+' operator in C?
Unary plus was added to C for symmetry with unary minus, from the Rationale for International Standard—Programming Languages—C:
Unary plus was adopted by the C89 Committee from several implementations, for symmetry with unary minus.
and it is not a no-op, it performs the integer promotions on its operand. Quoting from my answer to Does Unary + operator do type conversions?:
The draft C99 standard section 6.5.3.3
Unary arithmetic operators says:
The result of the unary + operator is the value of its (promoted) operand. The integer promotions are performed on the operand, and the result has the promoted type.
Worth pointing out that Annotated C++ Reference Manual(ARM) provides the following commentary on unary plus:
Unary plus is a historical accident and generally useless.
By 'no-op', do you mean the assembly instruction?
If so, then definitely not.
+4 is just 4 - the compiler won't add any further instructions.