编译器_keil的优化选项问题

在使用Keil编译时遇到代码优化问题,原本选择的default优化模式导致代码异常。研究后发现,该模式为level2优化,改用level0即可解决。优化级别对代码性能和大小有显著影响,level0更注重保持代码原貌。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近发现在keil编译的时候,出现莫名的问题,貌似代码有被优化掉的问题,后来查了下相关的资料,貌似懂了点。
我选择的是默认的default优化方式,上网看了下,默认的是level2级别优化,最后选择level0就没有问题了
下面是网上找的资料,介绍了优化功能介绍

Getting the Best Optimized Code for your Embedded Application 

ARM Compilation Tools 
The ARM Compilation Tools are the only compilation tool s co -developed with the ARM processors, and specifically 
designed to optimally support the ARM architecture. They are a result of 20 years of development, and are recognized as the 
industry -leading C and C++ compilation tools for the ARM, Thumb, and Thumb -2 instructions sets. 
The ARM Compilation tools consist of:  
•  The ARM Compiler, which enables you to compile C and C++ code. It is an optimizing compiler, and features 
command - line options to enable you to control the level of optimization  
•  Linker and Utilities, which assign addresses and lay out sections of code to form a final image  
•  A selection of libraries, including the ISO standard C libraries, and the MicroLIB C library which is optimized for 
embedded applications 
•  Assembler, which generates machine code instructions from  ARM, Thumb or Thumb-2 assembly- level   source code  
 
Compiler Options for Embedded Applications   
The ARM Compilation Tools include a number of compiler optimizations to help you best target your code for your chosen 
microcontroller device and   application area.   
They can be accessed from within µVision by clicking on Project –   Options for Target. 
T he options described this document  can be found on the Target   an d  C/C++   tabs  of   the  Options for Targets  dialog.  
 

MDK Compiler Optimizations   

•  Cross- Module  
Optimization  takes information from a prior build and uses it to place UNUSED functions into their 

own ELF section in the corresponding object file. This option is also known as Linker Feedback, and requires you to 
build your application twice to take adv antage of it for reduced code size.   
Cross-Module Optimization has been shown to reduce code size, by removing unused functions from your application. It 
can also improve the performance   of your application, by allowing modules to share inline code.  
 

•  The  M icroLIB   C library
has been optimized to reduce the size of embedded applications. It is a subset of the ISO 

standard C runtime library, and offers a tradeoff between functionality and code size. Some of the standard C library 
functions such as memcpy()   are  slower, while some features of the
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值