Freestanding: Remove strtok

Document number: P2937R0
Date: 2023-07-02
  Ben Craig <ben dot craig at gmail dot com>
Audience: Library Evolution Working Group

Changes from previous revisions

First revision!


Remove strtok from C++ freestanding, because C2X freestanding no longer includes strtok in C freestanding.

History and Rationale

strtok was added to C++ freestanding as part of P2338R4 (Freestanding Library: Character primitives and the C library). P2338R0 and P2338R1 did not include strtok, as strtok uses global storage that is difficult to synchronize in freestanding environments. (In practice, freestanding environments aren't guaranteed to have storage that is local to a thread, mutexes, or atomics larger than atomic_flag). In P2338R2 only added strtok because C2X added strtok to C freestanding.

In C2X CD2, C removed strtok from C freestanding. Now that strtok doesn't aid in C compatibility, C++ can now remove strtok from C++ freestanding.

Even though strtok is not required to avoid data races, good implementations do so. Freestanding shouldn't encourage implementations to provide poor implementations.


This paper’s wording is based on the working draft, [N4950], plus the anticipated inclusion of merging [P2338R4] (Freestanding Library: Character primitives and the C library).

Change in [version.syn]

Please update the value of the __cpp_lib_freestanding_cstring feature test macro.

#define __cpp_lib_freestanding_cstring      old-valnew-val // freestanding, also in <cstring>

Change in [cstring.syn]

Modify [cstring.syn].
char* strstr(char* s1, const char* s2); // freestanding, see [library.c] char* strtok(char* s1, const char* s2); // freestanding void* memset(void* s, int c, size_t n); // freestanding


[N4950] Thomas Köppe. 2023-05-10. Working Draft, Standard for Programming Language C++.
[P2338R4] Ben Craig. 2023-02-09. Freestanding Library: Character primitives and the C library