Proposal: API for thread-safe time zone functions

Clive D.W. Feather clive at demon.net
Fri Jun 8 10:02:09 UTC 2001


Garrett Wollman said:
> Precisely.  The reason is that the C language has opaque (incomplete)
> structures, but for technical reasons it cannot have opaque typedefs,

Huh ?

    struct timezone;                      // Opaque structure
    typedef struct timezone timezone_t;   // Opaque typedef

> and multiple typedefs for the same name in the same scope are not
> permitted even if they resolve to the same type.  (Unless C99 fixed
> that bug...?)

It's not a bug, it's a feature. Just the same as you can't declare the same
variable twice in a block.

> (Thus, if I am designing a library which exports a function that
> references a timezone, I can't use the `timezone_t' type without
> pulling in large amounts of namespace pollution, but I can easily do
> so with either a plain string, or a `struct timezone *'.

Um, you mean that you want to be able to refer to the type without
including the header ? Then just write both the above lines. But people
shouldn't be using your function without using your (public) header anyway.

You *are* using public and private headers, aren't you ? That is, users
of your library include <timezone.h>, which contains the above lines and
any function declarations you like. Your implementation includes that and
also includes a <timezone_p.h> or suchlike that redeclares struct timezone
with its contents.

-- 
Clive D.W. Feather  | Work:  <clive at demon.net>   | Tel:  +44 20 8371 1138
Internet Expert     | Home:  <clive at davros.org>  | Fax:  +44 20 8371 1037
Demon Internet      | WWW: http://www.davros.org | DFax: +44 20 8371 4037
Thus plc            |                            | Mobile: +44 7973 377646 



More information about the tz mailing list