当前位置:网站首页>深刻地认识到,编译器会导致编译结果的不同
深刻地认识到,编译器会导致编译结果的不同
2022-08-09 14:53:00 【黄铎彦】
以前以为说只要是windows系统,我都是c语言,api一样,编译结果也会一样。但是后来看了网友的实践,结合自己的观察,我强化了对课本内容的认识。
先上代码:
#include<stdio.h>
#pragma warning(disable:4996)//用devc++的话就不用这行
main()
{
int count = 0;
char i;
printf("输入由0和1组成的数串,按ctrl+z结束……");
while (scanf("%c", &i) != EOF)
if (i == '1')
count++;
printf("你输入了%d个1。", count);
}
上图为用vs编译的结果,下图为用devc++编译的结果。注意到,用vs编译的exe大小约为用devc++的一半。
接着看反汇编。
这下就非常明显了。用vs编译的程序,在调用第一个子过程,即执行call指令前,对rbp,rdi,rsp,rcx,rax这些寄存器进行了一系列的操作;而用devc++对rsp,rax这两个寄存器和内存进行了操作。并且可以发现对rsp的减法操作的减数也不一样。
再看看加载的dll的不同。
用vs编写的: | 用devc++编写的: |
“cTest.exe”(Win32): 已加载“D:\编程\cTest\x64\Debug\cTest.exe”。已加载符号。 “cTest.exe”(Win32): 已加载“C:\Windows\System32\ntdll.dll”。 “cTest.exe”(Win32): 已加载“C:\Windows\System32\kernel32.dll”。 “cTest.exe”(Win32): 已加载“C:\Windows\System32\KernelBase.dll”。 “cTest.exe”(Win32): 已加载“C:\Windows\System32\vcruntime140d.dll”。 “cTest.exe”(Win32): 已加载“C:\Windows\System32\ucrtbased.dll”。 | “test.exe”(Win32): 已加载“D:\编程\devctest\test.exe”。 “test.exe”(Win32): 已加载“C:\Windows\System32\ntdll.dll”。 “test.exe”(Win32): 已加载“C:\Windows\System32\kernel32.dll”。 “test.exe”(Win32): 已加载“C:\Windows\System32\KernelBase.dll”。 “test.exe”(Win32): 已加载“C:\Windows\System32\msvcrt.dll”。 |
上网查了发现,vcruntime140d.dll是来自visual c++ redistributable的:
还有ucrtbased.dll,注意,如果把这两个程序直接复制到另外一台电脑上,用vs编写的将不能正常运行。我有空的话会进一步探究这个问题。
所以课本里面说的没错,编译器也是影响程序执行结果的一个因素。
边栏推荐
猜你喜欢
Shell functions and arrays
如何设计一个高并发系统?
Matlab修改Consolas字体
相似图像的检测方法
Mathematica 数据分析(简明)
OpenSSF的开源软件风险评估工具:Scorecards
OpenSSF's open source software risk assessment tool: Scorecards
SNR 信噪比
Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution
启动报错:Caused by: org.apache.ibatis.binding.BindingException汇总解决
随机推荐
Shell -- -- -- -- -- - common gadgets, sort and uniq, tr, the cut
MongoDB adds permission management
FilenameFilter filters filenames
浅析Servlet三大容器的常用方法及其作用域
How to make your quantitative trading system have probabilistic advantages and positive return expectations?
Mysql两个引擎对比
回收站一直显示未清空的图标问题
Bean的生命周期
Shell functions and arrays
量化程序化交易都有哪些热点争议?
Play in the cloud | The ever-changing gameplay of Tianyi cloud computer
百度地图——鹰眼轨迹服务
爱因斯坦的光子理论
How do users correctly understand programmatic trading?
For programming trading, focusing on forecast or on countermeasures?
CV复习:BatchNorm
FilenameFilter过滤文件名
How to achieve stable profit through the stock quantitative trading interface?
运算符学习
内存泄露检测工具VLD(Visual Leak Detector)使用说明