Why do C languages require parens around a simple condition in an if statement? Why do C languages require parens around a simple condition in an if statement? javascript javascript

Why do C languages require parens around a simple condition in an if statement?


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.


Tell me how to interprit the following:

if x ++ b;

Looks silly but...

if( x ) ++b;

or

if( x++ ) b;

or perhaps "x" has an overloaded operator then...

if( x ++ b){;}

Edit:

As Martin York noted "++" has a higher precedence which is why I've had to add the operator overloading tidbit. He's absolutely right when dealing with modern compilers up until you allow for all that overloading goodness which comes with C++.


I think a better question would be "why would we want such a thing?" than "why don't we have it?". It introduces another otherwise unnecessary edge case into the lexer, just so you can avoid typing 4 extra characters; and adds complexity to the spec by allowing exceptions to a simple syntax that already supports all possible cases just fine. Not to mention toes the line of ambiguity, which in a programming language doesn't have much value.