前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则​Pro.lifetime:生命周期安全群组

C++核心准则​Pro.lifetime:生命周期安全群组

作者头像
面向对象思考
发布2020-11-11 10:42:24
4120
发布2020-11-11 10:42:24
举报

Pro.lifetime: Lifetime safety profile

Pro.lifetime:生命周期安全群组

Accessing through a pointer that doesn't point to anything is a major source of errors, and very hard to avoid in many traditional C or C++ styles of programming. For example, a pointer might be uninitialized, the nullptr, point beyond the range of an array, or to a deleted object.

通过没有指向任何内容的指针进行访问是错误的主要来源之一,这在许多传统的C或C ++编程风格中很难避免。例如,指针可能未初始化,空指针,指向数组范围之外或指向已删除的对象的指针。

See the current design specification here.

请参阅下面的最新设计规范。

https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/Lifetime.pdf

Lifetime safety profile summary(声明周期安全群组摘要):

  • Lifetime.1: Don't dereference a possibly invalid pointer: detect or avoid.
  • Lifetime.1:不要取消引用可能无效的指针:检测或避免
Impact(影响)

Once completely enforced through a combination of style rules, static analysis, and library support, this profile

通过结合样式规则,静态分析和库支持彻底实施后,此规则群组

  • eliminates one of the major sources of nasty errors in C++ 消除了C ++中令人讨厌的错误的主要来源之一
  • eliminates a major source of potential security violations 消除了潜在的安全违反的主要根源
  • improves performance by eliminating redundant "paranoia" checks 通过消除多余的“偏执”检查来提高性能
  • increases confidence in correctness of code 增加对代码正确性的信心
  • avoids undefined behavior by enforcing a key C++ language rule 通过执行关键的C ++语言规则避免未定义的行为

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#prolifetime-lifetime-safety-profile

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-11-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Pro.lifetime: Lifetime safety profile
  • Pro.lifetime:生命周期安全群组
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档