Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Relationship Between the C and C++ Standards?

I was writing this answer and I quoted from http://en.cppreference.com/w/cpp/string/byte/tolower#Parameters

Is not representable as unsigned char and does not equal EOF, the behavior is undefined

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

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.

But this concerns me for 2 reasons:

  1. How would I know what version of the C standard the C++ standard depends upon?
  2. 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?
like image 974
Jonathan Mee Avatar asked Jun 03 '16 12:06

Jonathan Mee


People also ask

What are the C standards?

What is the C programming language standard? It is the standard way defined for the compiler creators about the compilation of the code. The latest C standard was released in June 2018 which is ISO/IEC 9899:2018 also known as the C11.

What is the difference between ANSI C and C?

The standard was adopted by ISO in 1990 and ISO are now the standards body for the language - not ANSI. ANSI C merely refers to a particular standard for the C Programming Language - i.e. there is no difference, they refer to the same thing.

Is C similar to C+?

C++ is a superset of C, so both languages have similar syntax, code structure, and compilation. Almost all of C's keywords and operators are used in C++ and do the same thing. C and C++ both use the top-down execution flow and allow procedural and functional programming.


1 Answers

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:

  • ISO/IEC 9899:1999, Programming languages — C
  • ISO/IEC 9899:1999/Cor.1:2001(E), Programming languages — C, Technical Corrigendum 1
  • ISO/IEC 9899:1999/Cor.2:2004(E), Programming languages — C, Technical Corrigendum 2
  • ISO/IEC 9899:1999/Cor.3:2007(E), Programming languages — C, Technical Corrigendum 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].

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:

  • 17.2 [library.c], which describes the basic inclusion of the C standard library
  • Chapter 18 [language.support], which describes many of the <c:::> headers of the C++ standard library (those which offer the C standard library functionality).
like image 185
Angew is no longer proud of SO Avatar answered Oct 01 '22 16:10

Angew is no longer proud of SO