__STDC_LIB_EXT1__在gcc和clang中的可用性 [英] __STDC_LIB_EXT1__ availability in gcc and clang

查看:544
本文介绍了__STDC_LIB_EXT1__在gcc和clang中的可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Google的快速搜索没有找到任何内容,因此我将尝试在此处询问(因为许多参与gcc/clang的人都在这里闲逛)-__STDC_LIB_EXT1__在gcc/clang中的状态是什么?我们正在开发一个跨平台应用程序,我想使用<stdio.h>中的一些安全范围检查功能(奇迹般的功能可以在Visual Studio 2017中使用),但是无法使用Xcode 9.2编译代码.我假设Xcode使用的Clang版本已经过时,但是Ubuntu上的gcc 6.3.0表现相同.我正在尝试将 tmpnam_s 与以下示例一起使用:

Since a quick Google search did not find anything, I will try to ask here (since many people involved in gcc/clang hang around here) - What is the status of __STDC_LIB_EXT1__ in gcc/clang? We are developing a cross platform applicataion and I wanted to use some of the safe bounds checking functions from <stdio.h> (which by miracle are available on Visual Studio 2017), but could not compile the code with Xcode 9.2. I assumed maybe the clang version Xcode uses is outdated, but gcc 6.3.0 on Ubuntu behaves the same. I am trying to use tmpnam_s with the following sample:

#if defined(__STDC_LIB_EXT1__)
#define  __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#else
#error "__STDC_LIB_EXT1__ not defined"
#endif

int main(int argc, char** argv)
{
    char t[L_tmpnam_s]; 
    tmpnam_s(t, L_tmpnam_s);
    return 0;
}

但是编译失败,未定义宏:

But the compilation fails with the macro not being defined:

gcc -std=c11 test.c
test.c:5:2: error: #error "__STDC_LIB_EXT1__ not defined"
#error "__STDC_LIB_EXT1__ not defined"
^~~~~

我做错什么了吗?或者该功能集的支持很差?

Am I doing something wrong or this function set is simply poorly supported?

推荐答案

几乎不支持带有_s后缀的整套安全"功能. Microsoft用_s后缀编写了一组函数,并将其提交给C标准委员会以进行标准化.该委员会进行了一些更改(可以说是出于必要),并创建了技术报告TR 24731-1. C11标准ISO/IEC 9899:2011中将TR的轻度修改版本作为可选的附件K(规范性)包括在内.

The whole set of 'safe' functions with the _s suffixes is poorly supported. Microsoft wrote a set of functions with the _s suffixes and submitted that to the C standard committee to be standardized. The committee made some changes (arguably out of necessity), and created a technical report, TR 24731-1. A mildly modified version of the TR was included as optional Annex K (normative) in the C11 standard, ISO/IEC 9899:2011.

您可以在您使用TR-24731更安全"功能的答案中找到许多肮脏的细节吗?,特别是在我对该问题的答案中的注释中,尤其是在标准C委员会文档

You can find many sordid details in the answers to Do you use the TR-24731 "safer" functions?, especially in the notes in my answer to that question, and especially the link to the Standard C committee document N1967 Field Experience with Annex K — Bounds Checking Interfaces.

我不知道N1967提案的当前状态是什么,但有人建议说这是有道理的. N1967还包含指向支持附件K/TR-24731-1的库的链接-列表是有限的.

I don't know what the current status of the N1967 proposal is, but that it was suggested is telling. N1967 also contains links to libraries that support Annex K / TR-24731-1 — the list is limited.

请注意,Microsoft未实现C11标准指定的库.它实现了对标准的近似,但是存在一些关键差异.如果任何其他系统已经实现了该标准,那就更重要了-但是这些功能还没有以任何公认的形式实现(例如,GNU C库不会也不会支持它们).

Note that Microsoft does not implement the library specified by the C11 standard. It implements an approximation to the standard, but there are crucial differences. This would matter more if any other system had implemented the standard — but the functions have not been implemented in any widely accepted form (so, for example, the GNU C Library does not and will not support them).

这篇关于__STDC_LIB_EXT1__在gcc和clang中的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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