MSVC 2017下缺少C11 strerrorlen_s函数 [英] Missing C11 strerrorlen_s function under MSVC 2017

查看:363
本文介绍了MSVC 2017下缺少C11 strerrorlen_s函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从strerrorlen_s函数包括的标头 MSVC 2017 下的> C11标准.我需要它来分配要通过strerror_s获取的错误消息的空间.代码如下:

I'm trying to find which header to include for strerrorlen_s function from C11 standard under MSVC 2017. I need it for allocating space for error message which to get with strerror_s. The code is the following:

auto size = strerrorlen_s(errno) + 1;
char* errorReason = (char*)alloca(size);
strerror_s(errorReason, size, errno);
std::ostringstream oss;
oss << "Cannot open: " << fileName << " Reason: " << errorReason;
throw std::runtime_error(oss.str());

文档中的以下字词:

与所有边界检查的函数一样,仅在实现定义了__STDC_LIB_EXT1__并且用户在包含string.h之前将__STDC_WANT_LIB_EXT1__定义为整数常量1的情况下,才保证strerror_s和strerrorlen_s可用.

As with all bounds-checked functions, strerror_s and strerrorlen_s are only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including string.h.

MSVC 2017 没有定义__STDC_LIB_EXT1__,并且在包含string.h之前定义__STDC_WANT_LIB_EXT1__似乎没有效果.尽管strerror_s可用.

MSVC 2017 does not define __STDC_LIB_EXT1__ and it seems that defining __STDC_WANT_LIB_EXT1__ before including string.h doesn't have effect. Although strerror_s is available.

  • strerrorlen_s是否可以在 Windows 下与 MSVC 2017 一起使用?
  • 如果该功能不可用,是否可以通过其他方式获取错误消息的长度?
  • Windows strerror_s线程安全吗,因为在 Linux 下似乎不是,并且
  • Is strerrorlen_s available under Windows with MSVC 2017?
  • Is it possible some other way to get error message length if the function is not available?
  • Is strerror_s thread safe under Windows, because it seems that under Linux it's not and strerror_r must be used if there is need for thread safety, but it is not available on Windows?

推荐答案

Microsoft Visual Studio在用作C编译器时,大多遵循1990年的C标准.最近已进行了一些尝试,以将其更新为该语言的1999版本.他们仍然远远落后于此-编译器与2011年版本相去甚远.如果需要标准的C编译器,则不能使用VS.

Microsoft Visual Studio, when used as C compiler, mostly follows the 1990 version of the C standard. Some attempts have been made recently to update it to the 1999 version of the language. They are still far behind with that - the compiler is nowhere near the 2011 version. If you need a standard compliant C compiler you cannot use VS.

此外,您似乎在C ++模式下使用了编译器,但这并不能完全帮助C语言符合标准... C11和C ++ 11并不总是兼容的.

In addition, you seem to use the compiler in C++ mode which isn't exactly helping C standard compliance... C11 and C++11 are not always compatible.

也就是说,您要求的功能是可选的bounds-checking接口的一部分,我相信很少(如果有的话)编译器已经实现.边界检查接口中存在的某些功能作为非标准扩展存在于VS先前的C11中.它们不一定符合标准.

That being said, the function you ask for is part of the optional bounds-checking interface, which I believe very few, if any, compilers have yet implemented. Some functions present in the bounds-checking interface existed in VS prior C11 as non-standard extensions. They are not necessarily standard compliant.

不能保证库函数是可重入的.它们可能是线程安全的,也可能不是线程安全的.

There are no guarantees that library functions are re-entrant. They may or may not be thread-safe.

这篇关于MSVC 2017下缺少C11 strerrorlen_s函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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