n2524: string functions for freestanding implementations

Submitter:Philipp Klaus Krause
Submission Date:2020-05-11

Summary:

string functions for freestanding implementations.

This makes most of the functionality from string.h mandatory for freestanding implementations.

Justification:

Many string functions are commonly used, and most can be easily implemented. However, since they are not mandatory for freestanding implementtions, programs using them are not fully portable. However, most frestanding implementations already provide these functions (as witnessed by the widespread use of the Dhrystone benchmark for small embedded systems, which uses string functions).

The only functions from string.h that might be hard to implement on some systems are those that require dynamic memory or only make sense for locales. But even those could be implemented as stubs (i.e. always behaving as if out of memory and the locale-specific variants always behaving like the non-locale specific ones).

The Small Device C Compiler (SDCC) is a rather simple freestanding C implementation, that targets small devices, such as the Padauk PMS15A microcontroller (about 0.01€ each when bought in quantities of 10, 64 B RAM, 0.5 KW of 13-bit program memory, an 8-bit accumulator as the only register suitable for storing general data). It implements the full set of string.h functions from the N2479 draft. This shows that the string.h functions can easily be implemented efficiently even for tiny devices.

Do we want to make all of string.h mandatory for freestanding implementations?

Proposed change: §4p6: Add "string.h" to the list of headers freestanding implementations need to provide.

In case we decide "no" on the above question: Do we want to make most of string.h mandatory for freestanding implementations

Proposed change: §4p6: Add "string.h" to the list of headers freestanding implementations need to provide. And add the sentence "Notwithstanding the above, a conforming freestanding implementation is not required to provide the following functions from string.h: strdup, strndup, strcoll, strxfrm"

just before the last senetnce "A conforming implementation may have additional […]".

Would we like to see further proposals to make more of the standard library (e.g. uchar.h or errno.h, or abs, labs, llabs from stdlib.h) mandatory for freestanding implementations?