Possible Duplicate:
Please help me understanding the error a+++++b in C
Here is is the sample code, why "a+++++b" can not be compiled , but others can be?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
    int a = 0;
    int b = 0;
    int c = 0;
    c = a+++b;
    printf("a+++b is: %d\n", c);
    c = a = b = 0;
    c = a++ + ++b;
    printf("a++ + ++b is: %d\n", c);
    c = b = a = 0;
    c = a+++ ++b;
    printf("a+++ ++b is: %d\n", c);
    c = b = a = 0;
    c = a+++++b;      // NOTE: Can not be compiled here.
    printf("a+++++b is: %d\n", c);
    return 0;
}
That's because a+++++b is parsed as a ++ ++ + b and not as a ++ + ++ b[C's tokenizer is greedy]. a++ returns an rvalue and you cannot apply ++ on an rvalue so you get that error.
a+++b; // parsed as a ++ + b
a+++ ++b; // parsed as a ++ + ++ b
Read about Maximal Munch Rule.
The compiler is greedy so your expression
a+++++b
will be understood as
a++ ++ +b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With