MSVC 相当于 __attribute__ ((warn_unused_result))? [英] MSVC equivalent of __attribute__ ((warn_unused_result))?

查看:39
本文介绍了MSVC 相当于 __attribute__ ((warn_unused_result))?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 __attribute__ ((warn_unused_result)) 作为一种鼓励开发人员不要忽略函数返回的错误代码的方法非常有用,但我需要它与 MSVC 一起工作,以及gcc 和 gcc 兼容的编译器,例如 ICC.Microsoft Visual Studio C/C++ 编译器是否具有等效机制?(到目前为止,我已经尝试在 MSDN 中涉水但没有任何运气.)

I'm finding __attribute__ ((warn_unused_result)) to be very useful as a means of encouraging developers not to ignore error codes returned by functions, but I need this to work with MSVC as well as gcc and gcc-compatible compilers such as ICC. Do the Microsoft Visual Studio C/C++ compilers have an equivalent mechanism ? (I've tried wading through MSDN without any luck so far.)

推荐答案

它是 _Check_return_.有关类似注释和 此处 了解函数行为.自 MSVC 2012 起支持.

It's _Check_return_. See here for examples of similar annotations and here for function behaviour. It's supported since MSVC 2012.

示例:

_Check_return_
int my_return_must_be_checked() {
    return 42;
}

这篇关于MSVC 相当于 __attribute__ ((warn_unused_result))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆