c - Type definitions in POSIX/SUS headers -
this question concerns various types need defined in required headers of posix/sus standard.
some types needs defined in many header files, , i'm wondering what's correct , compliant way of achieving this.
for instance, @ <time.h>
header specification:
inclusion of header may make visible symbols <signal.h> header.
this straightforward, <signal.h>
included <time.h>
.
now this:
the clock_t, size_t, time_t, clockid_t, , timer_t types shall defined described in <sys/types.h>.
as understand it, means can't include <sys/types.h>
<time.h>
, expose more symbols required.
so can confirm this?
break standard compliance include <sys/types.h>
?
if so, think best solution create specific header each type, particular type can made visible anywhere, without worrying other symbols.
is there other solution?
and last thing, types c standard?
lots of types in posix/sus specification integral types, , may need have fixed width.
so ok standard include <stdint.h>
specific header, or break compliance?
you right exposing unwanted types , declarations additional headers non-conforming.
one trivial (but, in terms of time preprocessor spends opening files, expensive) solution have separate header each type, , whenever need, example, time_t
, do:
#include <types/time_t.h>
of course types/time_t.h
have appropriate multiple-inclusion guards.
there many other ways of achieving same. approach glibc , gcc use have special "needed" macros can define before including header asks nothing provide 1 or more types. solution expensive, moreso above, because breaks compilers' heuristics multiple-inclusion guards. compiler can't elide repeated inclusions; has parse file each time it's included.
the way in musl have single file, bits/alltypes.h
, includes definitions of types needed multiple headers , macros control exposed. it's generated simple sed script hides macro logic:
- http://git.musl-libc.org/cgit/musl/tree/arch/i386/bits/alltypes.h.in?id=9448b0513e2eec020fbca9c10412b83df5027a16
- http://git.musl-libc.org/cgit/musl/tree/include/alltypes.h.in?id=9448b0513e2eec020fbca9c10412b83df5027a16
- http://git.musl-libc.org/cgit/musl/tree/tools/mkalltypes.sed?id=9448b0513e2eec020fbca9c10412b83df5027a16
Comments
Post a Comment