本文介绍了为什么" A +++++ B"不能在GCC编译,但" A +++ B"," A ++ + ++ B"和" A +++ ++ B"可?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
这篇关于为什么&QUOT; A +++++ B&QUOT;不能在GCC编译,但&QUOT; A +++ B&QUOT;,&QUOT; A ++ + ++ B&QUOT;和&QUOT; A +++ ++ B&QUOT;可?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!