b*****d 发帖数: 23 | 1 int i = 1;
int j = 2;
int k = i +++ j;
k?
i?
j? |
b*****d 发帖数: 23 | 2 another one.
k = i+ +j;
【在 b*****d 的大作中提到】 : int i = 1; : int j = 2; : int k = i +++ j; : k? : i? : j?
|
w***g 发帖数: 5958 | 3 这个东西我觉得不同的编译器可能会给出不同的结果,未必有正确解。
【在 b*****d 的大作中提到】 : int i = 1; : int j = 2; : int k = i +++ j; : k? : i? : j?
|
l***8 发帖数: 149 | 4 The parser/tokenizer will always try to match the longest string. Therefore
when it encounters a sequence of "i+++j" it will generate four tokens:
(1) identifier "i"
(2) operator "++"
(3) operator "+"
(4) identifier "j" |
o**o 发帖数: 3964 | 5 before wasting time, think what you may achieve from this kind of tricks
【在 b*****d 的大作中提到】 : another one. : k = i+ +j;
|
b*****d 发帖数: 23 | 6 In fact, it is defined in C++ standard.
The reason is i++ has higher precedence than ++i.
Surprisingly.
so, i +++ j is
(i++)+j rather than
i+ (++j).
VS 2008 gives the correct answer.
【在 b*****d 的大作中提到】 : int i = 1; : int j = 2; : int k = i +++ j; : k? : i? : j?
|
b*****d 发帖数: 23 | 7 that's totally true.
so i++j is wrong, but i+ +j is okay.
Therefore
【在 l***8 的大作中提到】 : The parser/tokenizer will always try to match the longest string. Therefore : when it encounters a sequence of "i+++j" it will generate four tokens: : (1) identifier "i" : (2) operator "++" : (3) operator "+" : (4) identifier "j"
|
t****t 发帖数: 6806 | 8 it is defined in C++ standard, but your reason is wrong
it is defined in the tokenization process.
【在 b*****d 的大作中提到】 : In fact, it is defined in C++ standard. : The reason is i++ has higher precedence than ++i. : Surprisingly. : so, i +++ j is : (i++)+j rather than : i+ (++j). : VS 2008 gives the correct answer.
|
b*****d 发帖数: 23 | 9 puzzle...
how about i +++j,
the( ++j ) should be recognized as a token right?
【在 t****t 的大作中提到】 : it is defined in C++ standard, but your reason is wrong : it is defined in the tokenization process.
|
w****i 发帖数: 964 | 10 somehow remind me of 茴香豆的茴字有几种写法, hehe |
|
|
l***8 发帖数: 149 | 11 >> how about i +++j
No, "i +++j" is still tokenized as "i", "++", "+", "j".
This has nothing to do with operator precedence.
To force the parser to recognize (++j), you need to put a space between the 1st and 2nd
"+", like this: "i+ ++j". |
g*****g 发帖数: 34805 | 12 Why do you care, I'll make sure whoever writes this code
will get fired if I am the boss.
【在 b*****d 的大作中提到】 : int i = 1; : int j = 2; : int k = i +++ j; : k? : i? : j?
|
m*****e 发帖数: 4193 | 13 Wow...
I think it's good to know stuff, but this is very close to useless knowledge
to me.
the 1st and 2nd
【在 l***8 的大作中提到】 : >> how about i +++j : No, "i +++j" is still tokenized as "i", "++", "+", "j". : This has nothing to do with operator precedence. : To force the parser to recognize (++j), you need to put a space between the 1st and 2nd : "+", like this: "i+ ++j".
|
l***8 发帖数: 149 | 14 You probably will never care about this problem unless your job is to write
a compiler... So yes, it is 99.9% useless. |
b*****d 发帖数: 23 | 15 强人。
Thank you.
write
【在 l***8 的大作中提到】 : You probably will never care about this problem unless your job is to write : a compiler... So yes, it is 99.9% useless.
|
z***e 发帖数: 5393 | 16 C/C++是LL(1)或者LR(1),所以左边优先。
【在 b*****d 的大作中提到】 : puzzle... : how about i +++j, : the( ++j ) should be recognized as a token right?
|
d******n 发帖数: 42 | 17 who will actually write this?
maybe some tester? |