As discussed in this question, GCC defines nonstandard unary operator &&
to take the address of a label.
Why does it define a new operator, instead of using the existing semantics of the &
operator, and/or the semantics of functions (where foo
and &foo
both yield the address of the function foo()
)?
In mathematics, an unary operation is an operation with only one operand, i.e. a single input. This is in contrast to binary operations, which use two operands. An example is any function f : A → A, where A is a set. The function f is a unary operation on A.
Unary Increment (++) In this type, the Unary Operator is denoted by the '++' sign. It increases the value by 1 to the operand and then stores the value to the variable. It works for both Prefix and Postfix positions.
What Does Unary Operator Mean? A unary operator, in C#, is an operator that takes a single operand in an expression or a statement.
Unary Logical Operator The ! (logical negation) operator produces the value 0 if its operand is true (nonzero) and the value 1 if its operand is false (0).
Label names do not interfere with other identifiers, because they are only used in gotos. A variable and a label can have the same name, and in standard C and C++ it's always clear from the context what is meant. So this is perfectly valid:
name: int name; name = 4; // refers to the variable goto name; // refers to the label
The distinction between & and && is thus needed so the compiler knows what kind of name to expect:
&name; // refers to the variable &&name; // refers to the label
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With