当前位置:网站首页>深刻地认识到,编译器会导致编译结果的不同
深刻地认识到,编译器会导致编译结果的不同
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编写的将不能正常运行。我有空的话会进一步探究这个问题。
所以课本里面说的没错,编译器也是影响程序执行结果的一个因素。
边栏推荐
- docker安装单机版redis、集群版redis
- Grad CAM model visualization
- Similar image detection method
- 【OpenGL】三、OpenGL总结:OpenGL坐标系
- What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
- For programming trading, focusing on forecast or on countermeasures?
- 百度开源e-chart初探
- How to flexibly use the advantages of the quantitative trading interface to complement each other?
- 一种基于视频帧差异视频卡顿检测方案
- Servlet life cycle
猜你喜欢
随机推荐
Shell编程之正则表达式
卷积神经网络表征可视化研究综述(1)
JVM简学笔记
什么是模板引擎?常见的模板引擎有哪些?thymeleaf的常用指令介绍。
百度地图——地图找房功能
【基础版】整数加减乘除计算器
redis从入门到精通
navicat for Oraclel链接oracle 报错oracle library is not loaded的解决办法
6大论坛,30+技术干货议题,2022首届阿里巴巴开源开放周来了!
How to achieve stable profit through the stock quantitative trading interface?
英语议论文读写02 Engineering
在量化交易过程中,散户可以这样做
如何通过股票量化交易接口实现盈利稳定?
MySQL 原理与优化:Limit 查询优化
[MySql]实现多表查询-一对一,一对多
shell------常用小工具,sort,uniq,tr,cut
How can I know if quantitative programmatic trading is effective?
量化投资者是如何获取实时行情数据的呢?
大咖说·对话生态|当Confluent遇见云:实时流动的数据更有价值
Grad CAM 模型可视化









