我对C++中表达式的看法

dot99 2002-03-12 03:40:37
C++中的所有表达式均为函数,而C++中的函数入栈顺序是从右开始
所以:
x = 3;
y = (++x, x--, --x ++x, --x, x--);
中,栈及x的值的情况是
stack [3, 1, 2, 1, 1, 1
x [2, 1, 2, 1, 0, 1
y右边的运算顺序也是从右开始,不是同时进行的
y最先的值是1(由于先pop),最终y为3

不知对否?
...全文
43 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuicai 2002-03-14
  • 打赏
  • 举报
回复
如果你只是一个程序员,没必要去抠这个问题。
多用几个括号就行了。

如果你是理论专家,你可以去研究他,弄个新的编译算发出来。
liu_feng_fly 2002-03-14
  • 打赏
  • 举报
回复
默认的是__cdecl

__cdecl
Home | Overview | How Do I

Microsoft Specific —>

This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code. The following list shows the implementation of this calling convention.

Element Implementation
Argument-passing order Right to left
Stack-maintenance responsibility Calling function pops the arguments from the stack
Name-decoration convention Underscore character (_) is prefixed to names
Case-translation convention No case translation performed
liu_feng_fly 2002-03-14
  • 打赏
  • 举报
回复
好像C++里面默认的是__stdcall ?????
默认是cdecl,看看msdn吧
This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code. The following list shows the implementation of this calling convention.

Element Implementation
Argument-passing order Right to left
Stack-maintenance responsibility Calling function pops the arguments from the stack
Name-decoration convention Underscore character (_) is prefixed to names
Case-translation convention No case translation performed

dot99 2002-03-14
  • 打赏
  • 举报
回复
我在研究研究

先把分给了
Wugifer 2002-03-12
  • 打赏
  • 举报
回复
和编译器相关,在VC6.0和VC7.0中就不一样
dot99 2002-03-12
  • 打赏
  • 举报
回复
好像C++里面默认的是__stdcall
我这样理解就是从运算符重载来的
另外反编译后的指令也是这样的
tigerfox 2002-03-12
  • 打赏
  • 举报
回复
不一定,函数参数入栈。可以从左到右也可以从右到左。可以指定编译参数。
好像是: __clecs __stdcall __pascal
另外表达式就是表达式,其是有值的。和函数是两码事。
neccui 2002-03-12
  • 打赏
  • 举报
回复
表达式就是表达式,不是函数。
当然了,操作符重载例外。

而且从左到右还是从右到左,对表达式而言,都不一定的。看具体实现了。
不应该根据某个编译器的表现就下结论,我也曾经这样犯过一些错误。
dot99 2002-03-12
  • 打赏
  • 举报
回复
那应该怎么理解呢?
neccui 2002-03-12
  • 打赏
  • 举报
回复
dot99 () const;//永远的dot99() 理解错误。

xiel 2002-03-12
  • 打赏
  • 举报
回复
不一定
要看编译器
C++至今在二进制层无规定
cstpjl 2002-03-12
  • 打赏
  • 举报
回复
这个有用吗?

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧