Home >Backend Development >C++ >What Are the Uncommon Effects of Excess Parentheses in C ?
Parentheses in C usually do not affect program meaning, except in uncommon situations:
Parentheses can prevent argument-dependent name lookup (ADL) in function calls. While the form fun(arg) considers namespace-scope friend functions via ADL, (fun)(arg) does not, allowing precise function selection.
In list contexts (function arguments, initializer lists), the comma operator applies only within parentheses. Parentheses of the form a, (b, c), d enable the comma operator, while a, b, c, d do not.
Parentheses can resolve ambiguity in "vexing parse" situations, where a construct could be either a declaration or an expression. By surrounding a function-style type cast in parentheses, it can be clearly identified as an expression, avoiding parse ambiguity.
Extra parentheses can affect the deduced referenceness in decltype expressions. If the operand of decltype(e) is an unevaluated lvalue, enclosing it in parentheses (decltype((e))) deduces a const lvalue reference (&).
Parentheses can prevent errors in preprocessor macros by controlling macro expansion. For example, using parentheses around macro parameters avoids operator precedence issues, and enclosing function calls in parentheses protects against unwanted macro substitutions.
The above is the detailed content of What Are the Uncommon Effects of Excess Parentheses in C ?. For more information, please follow other related articles on the PHP Chinese website!