Re: [PATCH 1/2] system_data_types.7: Document size_t

Joseph Myers
2020-09-30T17:23:33Z

On Mon, 28 Sep 2020, Alejandro Colomar via Libc-alpha wrote:

> > To clarify, does POSIX _guarantee_ that all of those headers define this
> > type? (I admit I'm too lazy to search through the POSIX standard for an
> > answer to this).
>
> Yes, POSIX does guarantee that all those headers define the type.

For a lot of cases where a header contains a function using a type in its
prototype, current POSIX requires that type to be defined in the header,
but older POSIX permitted it (by virtue of the *_t reservation) but did
not require it unless XSI extensions were enabled.

The preferred glibc practice in such cases where older POSIX permitted the
definition and included functions using the type is not to make the
definition of the type in the header conditional on the POSIX version /
XSI extensions, but to enable the definition for all standards that
include the relevant function. (This simplifies the headers, and also
simplifies the conform/ tests because they then don't need to handle
testing for a declaration of a function without being able to write its
type in the most straightforward way.)

The headers still need to include feature test macro conditionals and
special handling where a header is required by some standard to declare a
function without defining the corresponding type name. (For example, ISO
C does not permit <stdio.h> to define va_list, so the header has to use an
implementation-namespace name for that type when declaring vprintf.)

--
Joseph S. Myers
joseph@codesourcery.com