I was writing this answer and I quoted from http://en.cppreference.com/w/cpp/string/byte/tolower#Parameters
我在写这个答案时引用了http://en.cppreference.com/w/cpp/string/byte/tolower#参数
Is not representable as unsigned char and does not equal EOF, the behavior is undefined
不表示为无符号字符,不等于EOF,行为是未定义的
When I went to inspect the edit that had added this phrase I found that the author's comment:
当我去查看添加了这个短语的编辑时,我发现作者的评论:
Can't use negative signed chars with any ctype.h function per C99 7.4/1
不能对任何ctype使用负符号字符。h函数/ C99 7.4/1
The author is citing from the C99 standard in C++ documentation. Is that valid? I couldn't find anything on the definition of this function in the C++ standard, so I must assume that it is valid.
作者引用了c++文档中的C99标准。这是有效的吗?我在c++标准中找不到这个函数的定义,所以我必须假设它是有效的。
But this concerns me for 2 reasons:
但这让我担忧有两个原因:
- How would I know what version of the C standard the C++ standard depends upon?
- 我如何知道c++标准依赖于什么版本的C标准?
- There are lists of the discrepancies between C and C++ everywhere. If I'm looking at the C standard with reference to C++ how could I possibly know whether the area I'm looking at has been overridden?
- 到处都有C和c++之间的差异列表。如果我正在查看与c++相关的C标准,我怎么可能知道我正在查看的区域是否被覆盖?
3 个解决方案
#1
34
For the first question:
第一个问题:
The C++ standard explicitly lists the C standard(s) on which it depends in its Normative references section. For C++14, [intro.refs] 1.2/1 happens to list C 99:
c++标准在其规范性参考一节中明确列出了它所依赖的C标准。(介绍c++ 14日。2/1发生在c99:
- ISO/IEC 9899:1999, Programming languages — C
- ISO/ iec989:1999,编程语言- C
- ISO/IEC 9899:1999/Cor.1:2001(E), Programming languages — C, Technical Corrigendum 1
- ISO/ iec9899:1999 /Cor.1:2001(E),编程语言- C,技术勘误表1
- ISO/IEC 9899:1999/Cor.2:2004(E), Programming languages — C, Technical Corrigendum 2
- ISO/ iec9899:1999 /Cor.2:2004(E),编程语言- C,技术勘误表2
- ISO/IEC 9899:1999/Cor.3:2007(E), Programming languages — C, Technical Corrigendum 3
- ISO/ iec9899:1999/Cor.3:2007(E),编程语言- C,技术勘误表3
For the second question:
第二个问题:
The C++ standard does not implicitly incorporate any parts of the C standard; all references to the C standard are explicit. A good source of information on where C++ deviates from C is Annex C, "Compatibility" of the C++ standard, particularly C.1 [diff.iso].
c++标准没有隐含地包含C标准的任何部分;所有对C标准的引用都是显式的。关于c++偏离C的一个很好的信息来源是附件C, c++标准的“兼容性”,特别是C.1 [diff.iso]。
Additionally, references to the C standard library are scattered throughout the description of the C++ standard library (chapters 17–30 in C++14). Of particular interest can be:
此外,对C标准库的引用分散在对c++标准库的描述中(c++ 14中的第17-30章)。特别的兴趣可以是:
- 17.2 [library.c], which describes the basic inclusion of the C standard library
- 17.2[图书馆。c],描述了c标准库的基本内容
- Chapter 18 [language.support], which describes many of the
<c:::>
headers of the C++ standard library (those which offer the C standard library functionality). - 第十八章(语言。它描述了c++标准库(提供c标准库功能的库)的许多 <:> 头。
#2
14
How would I know what version of the C standard the C++ standard depends upon?
我如何知道c++标准依赖于什么版本的C标准?
In C++ 14, it's ISO/IEC 9899:1999 (plus three corrigendums, so C99 in essence) as stated in 1.2 [intro.refs] in N4140. In C++98, it was C90, in C++17, it probably will be C11, but the C++ standard will always make that explicit.
在c++ 14中,它是ISO/IEC 9899:1999(加上三个corrigendums,即C99的本质),如1.2 [intro]中所述。参考文献]N4140。在c++ 98中,它是C90,在c++ 17中,它可能是C11,但是c++标准总是明确的。
If I'm looking at the C standard with reference to C++ how could I possibly know whether the area I'm looking at has been overridden?
如果我正在查看与c++相关的C标准,我怎么可能知道我正在查看的区域是否被覆盖?
You look in the C++ standard, it either explicitly imports the C definitions minus restrict
or any C behavior it wants or makes explicit modifications.
您可以查看c++标准,它要么显式导入C定义减去限制,要么任何它想要的C行为,要么进行显式修改。
Usually, reading good documentation instead of the standard itself will serve you just fine.
通常,阅读好的文档而不是标准本身就很好。
To address your initial question:
回答你最初的问题:
The author is citing from the C99 standard in C++ documentation. Is that valid?
作者引用了c++文档中的C99标准。这是有效的吗?
Yes, because
是的,因为
1 Tables 74 [contains
std::tolower
, me], 75, 76, 77, 78, and 79 describe headers<cctype>
,<cwctype>
,<cstring>
,<cwchar>
,<cstdlib>
(character conversions), and<cuchar>
, respectively.
2 The contents of these headers shall be the same as the Standard C Library headers<ctype.h>
,<wctype.h>
,<string.h>
,<wchar.h>
, and<stdlib.h>
and the C Unicode TR header<uchar.h>
, respectively, with the following modifications [none of those apply tostd::tolower
, me]:表74[包含std::tolower, me], 75、76、77、78和79描述了头部
、 、 、 、 (字符转换)、 。2这些标头的内容应与标准C库标头 ,< wctype。h >、 <字符串。h> ,< wchar。h >和< stdlib。h>和C Unicode TR头 相同。h>,分别进行以下修改[这些修改均不适用于std::tolower, me]: 。h>
21.8 [c.strings] in N4140
21.8(c。在N4140字符串)
#3
3
The edit is correct and this particular text has been in the standard since C90.
编辑是正确的,这个特定的文本自C90以来一直是标准的。
From C90 4.3
从人私下偷偷收藏盒式4.3
The header declares several functions useful for testing and mapping characters. In all cases the argument is an int , the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF . If the argument has any other value, the behavior is undefined.
头声明了几个对测试和映射字符有用的函数。在所有情况下,参数都是一个int型,其值应该可以表示为一个无符号字符,或者应该等于宏EOF的值。如果参数有其他值,则行为未定义。
From C11 7.4/1
从C11 7.4/1
The header declares several functions useful for classifying and mapping characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.
header声明了一些用于对字符进行分类和映射的函数。在所有情况下,参数都是一个int型,其值应该可以表示为一个无符号字符,或者应该等于宏EOF的值。如果参数有其他值,则行为未定义。
Identical text; C has always been like this. So it doesn't matter which C version your particular C++ version uses, because all C versions are equivalent.
相同的文本;C一直是这样的。因此,您的特定c++版本使用哪个C版本并不重要,因为所有的C版本都是等价的。
#1
34
For the first question:
第一个问题:
The C++ standard explicitly lists the C standard(s) on which it depends in its Normative references section. For C++14, [intro.refs] 1.2/1 happens to list C 99:
c++标准在其规范性参考一节中明确列出了它所依赖的C标准。(介绍c++ 14日。2/1发生在c99:
- ISO/IEC 9899:1999, Programming languages — C
- ISO/ iec989:1999,编程语言- C
- ISO/IEC 9899:1999/Cor.1:2001(E), Programming languages — C, Technical Corrigendum 1
- ISO/ iec9899:1999 /Cor.1:2001(E),编程语言- C,技术勘误表1
- ISO/IEC 9899:1999/Cor.2:2004(E), Programming languages — C, Technical Corrigendum 2
- ISO/ iec9899:1999 /Cor.2:2004(E),编程语言- C,技术勘误表2
- ISO/IEC 9899:1999/Cor.3:2007(E), Programming languages — C, Technical Corrigendum 3
- ISO/ iec9899:1999/Cor.3:2007(E),编程语言- C,技术勘误表3
For the second question:
第二个问题:
The C++ standard does not implicitly incorporate any parts of the C standard; all references to the C standard are explicit. A good source of information on where C++ deviates from C is Annex C, "Compatibility" of the C++ standard, particularly C.1 [diff.iso].
c++标准没有隐含地包含C标准的任何部分;所有对C标准的引用都是显式的。关于c++偏离C的一个很好的信息来源是附件C, c++标准的“兼容性”,特别是C.1 [diff.iso]。
Additionally, references to the C standard library are scattered throughout the description of the C++ standard library (chapters 17–30 in C++14). Of particular interest can be:
此外,对C标准库的引用分散在对c++标准库的描述中(c++ 14中的第17-30章)。特别的兴趣可以是:
- 17.2 [library.c], which describes the basic inclusion of the C standard library
- 17.2[图书馆。c],描述了c标准库的基本内容
- Chapter 18 [language.support], which describes many of the
<c:::>
headers of the C++ standard library (those which offer the C standard library functionality). - 第十八章(语言。它描述了c++标准库(提供c标准库功能的库)的许多 <:> 头。
#2
14
How would I know what version of the C standard the C++ standard depends upon?
我如何知道c++标准依赖于什么版本的C标准?
In C++ 14, it's ISO/IEC 9899:1999 (plus three corrigendums, so C99 in essence) as stated in 1.2 [intro.refs] in N4140. In C++98, it was C90, in C++17, it probably will be C11, but the C++ standard will always make that explicit.
在c++ 14中,它是ISO/IEC 9899:1999(加上三个corrigendums,即C99的本质),如1.2 [intro]中所述。参考文献]N4140。在c++ 98中,它是C90,在c++ 17中,它可能是C11,但是c++标准总是明确的。
If I'm looking at the C standard with reference to C++ how could I possibly know whether the area I'm looking at has been overridden?
如果我正在查看与c++相关的C标准,我怎么可能知道我正在查看的区域是否被覆盖?
You look in the C++ standard, it either explicitly imports the C definitions minus restrict
or any C behavior it wants or makes explicit modifications.
您可以查看c++标准,它要么显式导入C定义减去限制,要么任何它想要的C行为,要么进行显式修改。
Usually, reading good documentation instead of the standard itself will serve you just fine.
通常,阅读好的文档而不是标准本身就很好。
To address your initial question:
回答你最初的问题:
The author is citing from the C99 standard in C++ documentation. Is that valid?
作者引用了c++文档中的C99标准。这是有效的吗?
Yes, because
是的,因为
1 Tables 74 [contains
std::tolower
, me], 75, 76, 77, 78, and 79 describe headers<cctype>
,<cwctype>
,<cstring>
,<cwchar>
,<cstdlib>
(character conversions), and<cuchar>
, respectively.
2 The contents of these headers shall be the same as the Standard C Library headers<ctype.h>
,<wctype.h>
,<string.h>
,<wchar.h>
, and<stdlib.h>
and the C Unicode TR header<uchar.h>
, respectively, with the following modifications [none of those apply tostd::tolower
, me]:表74[包含std::tolower, me], 75、76、77、78和79描述了头部
、 、 、 、 (字符转换)、 。2这些标头的内容应与标准C库标头 ,< wctype。h >、 <字符串。h> ,< wchar。h >和< stdlib。h>和C Unicode TR头 相同。h>,分别进行以下修改[这些修改均不适用于std::tolower, me]: 。h>
21.8 [c.strings] in N4140
21.8(c。在N4140字符串)
#3
3
The edit is correct and this particular text has been in the standard since C90.
编辑是正确的,这个特定的文本自C90以来一直是标准的。
From C90 4.3
从人私下偷偷收藏盒式4.3
The header declares several functions useful for testing and mapping characters. In all cases the argument is an int , the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF . If the argument has any other value, the behavior is undefined.
头声明了几个对测试和映射字符有用的函数。在所有情况下,参数都是一个int型,其值应该可以表示为一个无符号字符,或者应该等于宏EOF的值。如果参数有其他值,则行为未定义。
From C11 7.4/1
从C11 7.4/1
The header declares several functions useful for classifying and mapping characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.
header声明了一些用于对字符进行分类和映射的函数。在所有情况下,参数都是一个int型,其值应该可以表示为一个无符号字符,或者应该等于宏EOF的值。如果参数有其他值,则行为未定义。
Identical text; C has always been like this. So it doesn't matter which C version your particular C++ version uses, because all C versions are equivalent.
相同的文本;C一直是这样的。因此,您的特定c++版本使用哪个C版本并不重要,因为所有的C版本都是等价的。