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.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3