Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我运行了一个 C 程序,在不同的 C 编译器上得到了不同的输出。下面是我的程序
void main() { int i=5; printf("%d%d%d%d%d",i++,i--,++i,--i,i); }
在 boarnland c++ 编译器 o/p 是
45545
在 gcc 上
45555
它真的依赖于编译器还是依赖于它的操作系统?
函数调用中的参数从左到右压入堆栈。评估是从堆栈中弹出。并且评估是从右到左的,因此是结果。
您不能依赖于函数参数的副作用的执行顺序。在这种情况下,两个编译器以不同的顺序执行副作用,产生不同的结果。