C++ Freestanding and Conditionally Supported

ISO/IEC JTC1 SC22 WG21 N3280 = 11-0050 - 2011-03-24

Lawrence Crowl, crowl@google.com, Lawrence@Crowl.org
Alberto Ganesh Barbati, ganesh@barbati.net

This paper is a revision of N3256 = 11-0026 - 2011-02-27.

Introduction
Wording Changes
    16.8 Predefined macro names [cpp.predefined]
    17.6.1.3 Freestanding implementations [compliance]
    30.3 Threads [thread.threads]

Introduction

CD comment DE 18 requested a macro to indicate the presence of threads. The response was a rather convoluted "ineffective <thread> header". This response failed to solve the real problem, and caused FCD comment GB 55. In addition, the change exacerbated incompatibilities between C and C++.

This paper provides the minimal fixes in this area for C++0x. They specifically satisfy

CD DE 18 Compile-time detection of advanced features

A macro that indicates the presence of threads in the core language is generally more applicable than one that only indicates the availability of library components. This approach is consistent with the wording in 1.10 [intro.multithread].

FCD GB 55 Freestanding <ratio> and <chrono>

The <mutex> header is more likely to be implemented in freestanding implementations than is <thread> and yet their freestanding requirements are opposite. Furthermore, there are many single-threaded embedded systems. So, <thread> should not be required of freestanding implementations. Consequently, <ratio> and <chrono> would not need to be freestanding and GB 55 would become moot.

C1X Freestanding Compatiblity

The set of freestanding headers required by C++ should include at least those required by C. Implementors will anyway because few would support only C++, so failing to support those headers simply invites an inconsistency between the standard and practice.

Wording Changes

16.8 Predefined macro names [cpp.predefined]

Add the following to the end of paragraph 2.

__STDCPP_THREADS__
Defined, and has the integer value constant 1, if and only if a program can have more than one thread of execution (1.10 intro.multithread).

17.6.1.3 Freestanding implementations [compliance]

Edit table 16 as follows.

Table 16 — C++ headers for freestanding implementations
SubclauseHeader(s)
17.6.1.2, C.2.2.3Named operators <ciso646>
18.2Types <cstddef>
18.3Implementation properties <cfloat> <limits> <climits>
18.4Integer types <cstdint>
.........
18.10Other runtime support <cstdalign> <cstdarg> <cstdbool>
.........
29Atomics <atomic>
30.3Threads <thread>

Edit paragraph 3 as follows.

The supplied version of the header <cstdlib> shall declare at least the functions abort, atexit, at_quick_exit, exit, and quick_exit (18.5). The supplied version of the header <thread> shall meet the same requirements as for a hosted implementation or including it shall have no effect. The other headers listed in this table shall meet the same requirements as for a hosted implementation.

30.3 Threads [thread.threads]

Edit the synopsis as follows.


namespace std {
  #define __STDCPP_THREADS__ __cplusplus

....