我发现 __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))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
读取输入文件,最快的方法?read input files, fastest way possible?(读取输入文件,最快的方法?)
在 C++ 中读取格式化输入的最简单方法?The easiest way to read formatted input in C++?(在 C++ 中读取格式化输入的最简单方法?)
从 .txt 文件读取到 C++ 中的二维数组Reading from .txt file into two dimensional array in c++(从 .txt 文件读取到 C++ 中的二维数组)
如何在 C++ 中模拟按键按下How to simulate a key press in C++(如何在 C++ 中模拟按键按下)
为什么在 cin.ignore() 之后没有 getline(cin, var) 读取Why doesn#39;t getline(cin, var) after cin.ignore() read the first character of the string?(为什么在 cin.ignore() 之后没有 getline(cin, var) 读取
scanf 格式输入的 cin 类比是什么?What is the cin analougus of scanf formatted input?(scanf 格式输入的 cin 类比是什么?)