关于参数有效性检验

Parameter Validation
https://msdn.microsoft.com/en-us/library/ksazx244.aspx
 
Most of the security-enhanced CRT(C运行时) functions and many of the preexisting(先前存在的) functions validate their parameters. This could include checking pointers for NULL, checking that integers fall into a valid range, or checking that enumeration values are valid. When an invalid parameter is found, the invalid parameter handler is executed.
note:注意这时提到一些验证参数的例子,翻译如下:
一、指针是否为空。
二、整型是否会落入一个有效的范围。
三、检查枚举类型是否有效。
而且如果一个无效的参数被发现,会执行相应的无效参数处理机制。是每一种类型的参数异常对应一种处理机制吗?

Invalid Parameter Handler Routine
--------------------------------------------------------------------------------
The behavior of the C Runtime when an invalid parameter is found is to call the currently assigned invalid parameter handler. The default(note:这里应该指的是运行时,而不是调试时) invalid parameter invokes Watson crash reporting, which causes the application to crash and asks the user if they want to load the crash dump to Microsoft for analysis. In Debug mode, an invalid parameter also results in a failed assertion.

This behavior can be changed by using the function _set_invalid_parameter_handler to set the invalid parameter handler to your own function.(note:你可以通过set_invalid_parameter_handler 函数来设定无效参数 的处理机制到你自己定义的函数) If the function you specify does not terminate the application, control is returned to the function that received the invalid parameters, and these functions will normally cease execution, return an error code(note:这个收到无效参数的函数会正常地结束执行,并返回一个错误码。注意反省一下,自己在处理相应的问题时,对于非法输入是都能返回相应的错误码。), and set errno to an error code. In many cases, the errno value and the return value are both EINVAL, indicating an invalid parameter. In some cases, a more specific error code is returned, such as EBADF for a bad file pointer passed in as a parameter. For more information on errno, see errno, _doserrno, _sys_errlist, and _sys_nerr.

-------------------

ASK:为什么返回值中有了错误码,还要另外再用一个errno

转载于:https://my.oschina.net/ray1421/blog/789329

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值