当前位置:网站首页>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可以改变.
边栏推荐
猜你喜欢
Jetson Orin平台4-16路 GMSL2/GSML1相机采集套件推荐
交换机和路由器技术-35-NAT转PAT
如何给网页添加icon图标?
「转」“搜索”的原理,架构,实现,实践,面试不用再怕了
我的LaTeX入门
The sword refers to offer_abstract modeling capabilities
Do you understand how the Selenium automated testing framework works?
论文笔记:BBN: Bilateral-Branch Network with Cumulative Learningfor Long-Tailed Visual Recognition
剑指offer_抽象建模能力
优化是一种习惯●出发点是“站在靠近临界“的地方
随机推荐
zabbix构建企业级监控告警平台
1815. 得到新鲜甜甜圈的最多组数 状态压缩
如何给网页添加icon图标?
交换机和路由器技术-27-OSPF路由重分发
分层架构&SOA架构
Selenium自动化测试框架工作原理你明白了吗?
Object Creation and Display Transformation
交换机和路由器技术-31-扩展ACL
论文笔记:Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
如何将360全景图导出高清短视频分享到视频平台上?
Network Skill Tree
网络协议1
【yolov7系列三】实战从0构建训练自己的数据集
Switch and Router Technology - 25 - OSPF Multi-Area Configuration
Smart Pointer Notes
How IP-Guard prohibits running U disk programs
Paper Notes: Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
优化是一种习惯●出发点是“站在靠近临界“的地方
Merkel Studio--OpenEuler Training Notes (1)
Layered Architecture & SOA Architecture