1

I was just curious because in my homework it says that the following statement is false:

The C++ Standard Library functions and classes are not included in every C++ implementation.

I don't think that the Standard Library is included in every C++ implementation unless you add (#include) the appropriate headers, right? In that case, I think that the above statement is true, not false.

Is the statement true or false?

trusktr
  • 44,284
  • 53
  • 191
  • 263

3 Answers3

5

Looks like unfortunate overloading of the word "include".

Your C++ compiler comes with files containing the standard library. So they are "included". But they aren't #include-d, you have to write #include in your source files to get access to the standard library.

In addition, there are hosted and freestanding implementations. Here's what the Standard says:

Two kinds of implementations are defined: a hosted implementation and a freestanding implementation. For a hosted implementation, this International Standard defines the set of available libraries. A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries (17.6.1.3).

Since the statement says "every C++ implementation", and freestanding implementations do not include the entire C++ Standard Library, the statement is TRUE.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • The quote is from section 1.4 Implementation compliance `[intro.compliance]` of C++11 (draft n3290) The language is identical to C++03 (same section). – Ben Voigt Jan 21 '12 at 20:09
  • Hey @BenVoigt, Can you link "Standard" where you said "Here's what the Standard says" to the appropriate page? Thanks! – trusktr Jan 21 '12 at 20:13
  • 1
    As computer scientists/programmers/engineers we tend to be a very picky pedantic bunch (a necessity of the field). Though I consider this answer to be correct in the strict sense of the standard. I would also note that when people generally talk about C++ and compilers we are generally (99% of the time (like 80% of stats this one is made up)) talking about hosted implementations and freestanding discussions or generally the exception for most developers. – Martin York Jan 21 '12 at 20:19
  • 1
    @Loki: I don't want my compiler to perform optimizations that are correct 99% of the time either. – Ben Voigt Jan 21 '12 at 20:20
  • @BenVoigt: I am just looking at it from a teachers point of view. I am sure during the course they have never touched a freestanding compiler (so there is some context that is not explicitly stated in the question). Though I agree that it is then a badly worded question. – Martin York Jan 21 '12 at 20:22
  • @trusktr: Normally you don't quote page numbers as they can change between versions of the standard. We use sections and paragraph numbers. You can get a copy here: http://stackoverflow.com/a/4653479/14065 look up the section Ben quoted: [intro.compliance] – Martin York Jan 21 '12 at 20:24
3

The statement is true (and your homework instructor is wrong). The standard distinguishes in 17.4.1.3 between hosted and freestanding implementations. Only the hosted implementations are required to implement the C++ standard library. The freestanding implementation is only required to have these headers:

18.1 Types <cstddef>
18.2 Implementation properties <limits>
18.3 Start and termination <cstdlib>
18.4 Dynamic memory management <new>
18.5 Type identification <typeinfo>
18.6 Exception handling <exception>
18.7 Other runtime support <cstdarg>
Nordic Mainframe
  • 28,058
  • 10
  • 66
  • 83
1

If the C++ implementation claims to be a conforming implementation of the C++ Standard (ISO/IEC 14882) it needs to include an implementation of both the compiler and the standard C++ library. Even for a conforming implementation the standard library doesn't have to be complete, though: there is a difference between free-standing and hosted implementations. While the former is only required to have very basic support, the latter requires that the entire implementation is provide (I think it is this way around but I keep getting confused about the terms; it may be the other way around).

That said, there are various compilers which don't ship with more than a very basic library and the basic library they ship with consists of things the compiler either has to do or the run-time absolutely need to run. They don't claim to be conforming implementations, however. You would need to combine them with a library but there are several libraries you can purchase (or download, some of them are free but the free ones seem to only work with a couple of specific compilers).

Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380