当前位置:网站首页>The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
2022-07-06 17:38:00 【Wzzzzzzx】
void foo() {
QVariant a = 10;
QVariant b = 20;
int c = add(a, b);
return c;
}
int add(const QVariant &a, const QVariant &b) {
int left = a.value<int>();
int right = b.value<int>();
return a + b;
}
Here's add
function , Although it's ours foo
It will be called internally , But if it's not a performance bottleneck , Better be right add
Check the parameters of .
The reason is that the subsequent maintainers are not as clear about the internal implementation of the function as we are , Some wrong types may be passed in .
This involves a defensive programming problem , We are the function writers , Try to prevent others from introducing a wrong thing , And try to solve this wrong thing .
This is similar to the question whether the smart pointer can take out the raw pointer and pass it into the function as an argument . In some cases , If we have enough knowledge about the internal implementation of functions , Ensure that it does not release the resource indicated by the pointer , We can pass the bare pointer .
One is the writer's perspective , One is the perspective of the caller .
边栏推荐
- JUnit unit test
- [VNCTF 2022]ezmath wp
- How does wechat prevent withdrawal come true?
- 华为认证云计算HICA
- Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
- Models used in data warehouse modeling and layered introduction
- connection reset by peer
- Jetpack compose 1.1 release, based on kotlin's Android UI Toolkit
- [mmdetection] solves the installation problem
- CTF reverse entry question - dice
猜你喜欢
05 personal R & D products and promotion - data synchronization tool
当前系统缺少NTFS格式转换器(convert.exe)
EasyRE WriteUp
Wu Jun's trilogy experience (VII) the essence of Commerce
Shawshank's sense of redemption
Selenium test of automatic answer runs directly in the browser, just like real users.
04个人研发的产品及推广-数据推送工具
Models used in data warehouse modeling and layered introduction
C# WinForm中DataGridView单元格显示图片
信息与网络安全期末复习(完整版)
随机推荐
【MySQL入门】第三话 · MySQL中常见的数据类型
Based on infragistics Document. Excel export table class
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
The NTFS format converter (convert.exe) is missing from the current system
Jetpack compose 1.1 release, based on kotlin's Android UI Toolkit
Shawshank's sense of redemption
Uipath browser performs actions in the new tab
【逆向初级】独树一帜
Development and practice of lightweight planning service tools
07 personal R & D products and promotion - human resources information management system
C# WinForm中DataGridView单元格显示图片
JVM garbage collector part 2
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
Final review of information and network security (full version)
【逆向中级】跃跃欲试
Total / statistics function of MySQL
自动化运维利器ansible基础
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
Remote code execution penetration test - B module test