avatar
b*d
2
int i = 1;
int j = 2;
int k = i +++ j;
k?
i?
j?
avatar
v*d
3
...
avatar
b*d
4
another one.
k = i+ +j;

【在 b*****d 的大作中提到】
: int i = 1;
: int j = 2;
: int k = i +++ j;
: k?
: i?
: j?

avatar
v*d
5
怎么换另一个形象啊 我换衣服了啊
怎么还是这个
avatar
w*g
6
这个东西我觉得不同的编译器可能会给出不同的结果,未必有正确解。

【在 b*****d 的大作中提到】
: int i = 1;
: int j = 2;
: int k = i +++ j;
: k?
: i?
: j?

avatar
v*d
7
。。。
avatar
l*8
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"
avatar
v*d
9
,,
avatar
o*o
10
before wasting time, think what you may achieve from this kind of tricks

【在 b*****d 的大作中提到】
: another one.
: k = i+ +j;

avatar
v*d
11
晕 不会用
avatar
b*d
12
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?

avatar
v*d
13
now
avatar
b*d
14
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"

avatar
H*o
15
10分。系统有延迟吧,没关系的。

【在 v***d 的大作中提到】
: now
avatar
t*t
16
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.

avatar
k*y
17
10分

【在 v***d 的大作中提到】
: ,,,,,
avatar
b*d
18
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.

avatar
w*i
19
somehow remind me of 茴香豆的茴字有几种写法, hehe
avatar
l*8
20
>> 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".
avatar
g*g
21
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?

avatar
m*e
22
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".

avatar
l*8
23
You probably will never care about this problem unless your job is to write
a compiler... So yes, it is 99.9% useless.
avatar
b*d
24
强人。
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.

avatar
z*e
25
C/C++是LL(1)或者LR(1),所以左边优先。

【在 b*****d 的大作中提到】
: puzzle...
: how about i +++j,
: the( ++j ) should be recognized as a token right?

avatar
d*n
26
who will actually write this?
maybe some tester?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。