当前位置:网站首页>It is deeply recognized that the compiler can cause differences in the compilation results
It is deeply recognized that the compiler can cause differences in the compilation results
2022-08-09 16:17:00 【Huang Duoyan】
I used to think that as long as it is a windows system, I am in C language, the api is the same, and the compilation result will be the same.But after reading the practice of netizens and combining my own observations, I strengthened my understanding of the content of the textbook.
Code first:
#include#pragma warning(disable:4996)//If you use devc++, you don't need this linemain(){int count = 0;char i;printf("Enter a number string consisting of 0 and 1, press ctrl+z to end...");while (scanf("%c", &i) != EOF)if (i == '1')count++;printf("You entered %d 1s.", count);} 
The picture above shows the result of compiling with vs, and the picture below shows the result of compiling with devc++.Note that the exe compiled with vs is about half the size of devc++.
Next, look at the disassembly.

This is very obvious.The program compiled with vs performs a series of operations on the registers rbp, rdi, rsp, rcx, rax before calling the first sub-process, that is, before executing the call instruction; and using devc++ on the two registers rsp, raxand memory operation.And it can be found that the subtrahend of the subtraction operation on rsp is also different.
Look at the difference in the loaded dll again.
| Written in vs: | Written in devc++: |
| "cTest.exe" (Win32): "D:\Programming\cTest\x64\Debug\cTest.exe" loaded.Symbols loaded. "cTest.exe" (Win32): "C:\Windows\System32\ntdll.dll" loaded. "cTest.exe" (Win32): "C:\Windows\System32\kernel32.dll" loaded. "cTest.exe" (Win32): "C:\Windows\System32\KernelBase.dll" loaded. "cTest.exe" (Win32): "C:\Windows\System32\vcruntime140d.dll" loaded. "cTest.exe" (Win32): "C:\Windows\System32\ucrtbased.dll" loaded. | "test.exe" (Win32): "D:\Programming\devctest\test.exe" loaded. "test.exe" (Win32): "C:\Windows\System32\ntdll.dll" loaded. "test.exe" (Win32): "C:\Windows\System32\kernel32.dll" loaded. "test.exe" (Win32): "C:\Windows\System32\KernelBase.dll" loaded. "test.exe" (Win32): "C:\Windows\System32\msvcrt.dll" loaded. |
I checked online and found that vcruntime140d.dll is from visual c++ redistributable: 
There is also ucrtbased.dll. Note that if you copy these two programs directly to another computer, the ones written in vs will not work properly.I will explore this further when I have time.
So it's true in the textbook that the compiler is also a factor that affects the results of program execution.
边栏推荐
猜你喜欢
随机推荐
Grad CAM model visualization
Shell programming loop statement
大咖说·对话生态|当Confluent遇见云:实时流动的数据更有价值
如何让你的量化交易系统具有概率优势,具有正向收益预期呢?
What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
量化投资者是如何获取实时行情数据的呢?
Analysis: Which method is used to build a stock quantitative trading database?
For programming trading, focusing on forecast or on countermeasures?
Servlet life cycle
My MySQL database was attacked and deleted for ransom, forcing me to use all my might to recover data
docker安装seata(指定配置文件、数据库、容器数据卷等)
分析:通过哪种方法来建立股票量化交易数据库?
通用的双向循环列表的几个比较重要的函数操作
数据库多表链接查询的方式
EasyExcel的应用
xshell7连接工具下载
.Net Core 技巧小结
Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution
docke安装mysql以及主从搭建(并且指定数据生成路径)
常见编译问题








