当前位置:网站首页>C Language: Practical Debugging Tips
C Language: Practical Debugging Tips
2022-08-11 04:55:00 【so-and-so Xiaolu】
Why learn debugging skills?
Because we will writebug,And sometimes I can't find it myself.
一名优秀的程序员是一名出色的侦探.
每一次调试都是尝试破案的过程
How should we find and modifybug呢?
目录
Use an example to understandconst和assert
1.程序的两种类型(debug和release类型)
- Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序.
- Release 称为发布版本,它往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很好地使用.
debug是程序员(That's us gangsters)try,It will have a debugging process.
release是用户使用的,It gives the result directly
If we were to debug,只能在debug的环境下
Several common shortcut keys
F5
启动调试,经常用来直接跳到下一个断点处.
F9
创建断点和取消断点
断点的重要作用,可以在程序的任意位置设置断点.
这样就可以使得程序在想要的位置随意停止执行,继而一步步执行下去.
F10
逐过程,通常用来处理一个过程,一个过程可以是一次函数调用,或者是一条语句.
F11
逐语句,就是每次都执行一条语句,但是这个快捷键可以使我们的执行逻辑进入函数内部(这是最
长用的).
CTRL + F5
开始执行不调试,如果你想让程序直接运行起来而不调试就可以直接使用.
F5和F9是搭配使用的,F9is to set a breakpoint on any line,而F5Jump directly to the breakpoint,Then stop there.
Various debug windows
Want to enter debug windows such as automatic windows,得先按F10!Those windows will appear
a.自动窗口
This will automatically jump out of the variable when running a line,You can't look at the variables you want to look at,So this method is inconvenient for us
b.局部变量
The window for local variables is one below the automatic window.
The local variables window is where you point to,It shows you the values of all the local variables in that part.
c.监视
Watching allows us to see the variable or address we want!!!
It is easier to monitor
d.内存
Similarly, windows such as function stacks have not been tried,但操作方法一样.
编程常见的错误
a.编译型错误
Basically a syntax error like this,This syntax error will arise as we type more code,You can find out for yourself,and correct it yourself,相对简单.
b.链接型错误
Basically it is composed of undefined functions or uninitialized variables,This is the same error as the previous one,相对简单、.
c.运行时错误
This runtime error refers to,可以运行成功,But the running result is wrong,This error is often the most fatal.
示例1演示:
我们是求1!+2!+3!的值,我们通过监视,发现3!的值变为12,而不是6.Here we analyze it,Find the last count2!The value is retained without reset,所以造成了错误.在11行加一句ret=1就可以了.
Use an example to understandconst和assert
assertYou can tell if something went wrong,例如:Here it is judged whether the passed is a null pointer,If it is a null pointer, an error is reported.
assert的头文件是#include
我们可以利用assert来提高代码的安全性.
constCan be placed in two positions,一个位置是*的左边,一个是*的右边
放在*的左边,*p不能改变了,p可以改变.
放在*的右边,pThis address cannot be changed,*p可以改变.
边栏推荐
- [QNX Hypervisor 2.2用户手册]10.15 vdev timer8254
- 延长经济保险(jeecgboot)
- 如何阅读论文
- 绿盾加密如何顺利切换成IP-Guard加密
- 论文笔记:Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
- JVM 垃圾回收的概述与机制
- 对象的创建以及显示转换
- async(异步)和await的使用
- Switches and routers technology - 26 - configure OSPF peripheral area
- 简历里写了会代码,却依然过不了面试这一关
猜你喜欢
Switch and Router Technology - 28 - NSSA Areas for OSPF
How IP-Guard prohibits running U disk programs
如何给网页添加icon图标?
交换机和路由器技术-31-扩展ACL
延长经济保险(jeecgboot)
论文笔记:Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
The use of async (asynchronous) and await
无线电射频能量的收集
交换机和路由器技术-34-动态NAT
ALSA音频架构 -- snd_pcm_open函数分析
随机推荐
交换机和路由器技术-32-命名ACL
无线电射频能量的收集
关于pom.xml文件
Summary of c language fprintf, fscanf, sscanf and sprintf function knowledge points
MQ框架应用比较
Events and scheduled tasks in Mysql
网络技能树
【小记】BatchSize的数值是设置的越大越好吗
交换机和路由器技术-25-OSPF多区域配置
C语言题解:谁是凶手!
[Web3 series development tutorial - create your first NFT (9)] How to view your NFT in the mobile wallet
zabbix构建企业级监控告警平台
Three 】 【 yolov7 series of actual combat from 0 to build training data sets
Network Skill Tree
ALSA音频架构
自研能力再获认可,腾讯云数据库入选 Forrester Translytical 报告
破解事务性工作瓶颈,君子签电子合同释放HR“源动力”!
The use of async (asynchronous) and await
Paper Notes: BBN: Bilateral-Branch Network with Cumulative Learning for Long-Tailed Visual Recognition
1815. 得到新鲜甜甜圈的最多组数 状态压缩