Why do C languages require parens around a simple condition in an if statement?
c, c#, c++, java, javascript
Solution
If there are no brackets around expressions in `if` constructs, what would be the meaning of the following statement?
if x * x * b = NULL;
Is it
if (x*x)
(*b) = NULL;
or is it
if (x)
(*x) * b = NULL;
(of course these are silly examples and don't even work for obvious reasons but you get the point)
TLDR: Brackets are required in C to remove even the possibility of any syntactic ambiguity.
Problem
It sounds stupid, but over the years I haven't been able to come up with a use case that would require this. A quick google search didn't reveal anything worthwhile. From memory there was a use case mentioned by Bjarne Stroustrup but i can't find a reference to it. So why can't you have this in C languages: ``` int val = 0; if val doSomehing(); else doSomehinglse(); ``` I can accept the "we couldn't be bothered adding support to lexer" reason, I just want to figure out if this syntax breaks other language constructs. Considering how many whacky syntax features there are in C/C++, i hardly think this would have added much complexity.