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

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

问题描述

我发现 __ attribute__((warn_unused_result))来作为鼓励开发人员不要忽视错误codeS由函数返回的方法很有用,但我这需要用MSVC的工作,以及海湾合作委员会和gcc兼容的编译器,如ICC。做微软的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_ret​​urn _ 。请参见这里类似标注的例子和的这里功能的行为。它自2012年MSVC的支持。

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天全站免登陆