由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - i +++ j
相关主题
又一个初级问题: C++中多如牛毛的#define格式C++ Q03:
operator overloading (C++)C++ Q07: unnamed namespace
where is popen defined?深情的呼唤师傅们!C++做题做不出来啦!
电话面试题一问 (转载)请教C++11
C++的库XSL question
Any difference between class and typename identifier?javascript function-ask for help
【请教】mpicc 和 mpiCC编译问题How to avoid getting "has encountered a problem and needs to close" window
程序怎么不认识class, namespace等identifier呀?ssh question on linux
相关话题的讨论汇总
话题: int话题: operator话题: c++话题: defined话题: therefore
进入Programming版参与讨论
1 (共1页)
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
相关主题
Any difference between class and typename identifier?C++ Q03:
【请教】mpicc 和 mpiCC编译问题C++ Q07: unnamed namespace
程序怎么不认识class, namespace等identifier呀?深情的呼唤师傅们!C++做题做不出来啦!
进入Programming版参与讨论
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?
1 (共1页)
进入Programming版参与讨论
相关主题
ssh question on linuxC++的库
[合集] Effecive c++ 真那么好? (转载)Any difference between class and typename identifier?
VC 6 有时死机问题【请教】mpicc 和 mpiCC编译问题
请教:记录访问者IP时,发生的奇怪问题!程序怎么不认识class, namespace等identifier呀?
又一个初级问题: C++中多如牛毛的#define格式C++ Q03:
operator overloading (C++)C++ Q07: unnamed namespace
where is popen defined?深情的呼唤师傅们!C++做题做不出来啦!
电话面试题一问 (转载)请教C++11
相关话题的讨论汇总
话题: int话题: operator话题: c++话题: defined话题: therefore