Rule for ignoring spaces in a C expression

In many C expressions, spaces are ignored (for example: in the case of ** b, where b is a pointer, spaces are ignored). But in few cases they cannot be ignored. We get a lot of SO posts on x +++ y and related ( C ++ spaces in statements, what are the rules ). I know that x +++ y really means (x ++) + Y because of the higher precedence for postfix. There is also a difference between x ++ + y and x + ++ y. Thus, spaces are not always ignored in c expressions. I want to know what is the rule for spaces in expressions. Where is it defined? When are they not ignored? Is it when two operators come in one after the other, especially increment / decrement operations?

+3


source to share


1 answer


The space is only relevant for token creation. + and ++ are valid tokens. The rule in C is that the token is formed from the longest sequence of characters that would create a valid token, so "++" without a space becomes the only "++" token, and "+ +" with a space becomes two "+". Since the "+++" token is missing, "+++" becomes the "++" token, followed by the "+" token.



+6


source







All Articles