加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 为合同指定违规处理程序

发布时间:2020-12-16 07:23:35 所属栏目:百科 来源:网络整理
导读:拉普斯维尔的C 20工作草案采纳了 Support for contract based programming in C++ .此语言功能的一部分是违反处理程序的概念,当违反合同时将调用该处理程序. Herb Sutter’s trip report指出: You get to install your own violation handler and ship a re
拉普斯维尔的C 20工作草案采纳了 Support for contract based programming in C++
.此语言功能的一部分是违反处理程序的概念,当违反合同时将调用该处理程序.

Herb Sutter’s trip report指出:

You get to install your own violation handler and ship a release build with the option of turning on enforcement at run time.

但是,本文补充说,[dcl.attr.contract]的措辞是:

The violation handler of a program is a function of type “noexceptopt
function of (lvalue reference to const std?::?contract_-violation) returning void”,and is specified in an implementation-defined manner. […] There should be no programmatic way of setting or modifying the violation handler. It is implementation-defined how the violation handler is established for a program and how the std?::?contract_-violation ([support.contract.cviol]) argument value is set,except as specified below.

这对我来说非常不清楚.实现如何允许我以非编程方式设置自己的违规处理程序?我将在gcc,clang和msvc上做些什么?

解决方法

How might an implementation allow me to set my own violation handler,in a non-programmatic way?

这是为了确定实现,但我更怀疑它将是某种命令行参数.您将命名一个函数,编译器/链接器将使其成为违规处理程序.如果不是这样,那么他们可能会选择您实现的某个特定功能名称.

这里的要点是从C抽象模型的角度来看,所使用的函数是静态的.当编译器启动时,它确切地知道将调用哪个函数,就像系统对main的调用一样,以及处理main的返回值的程序部分.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读