tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Having to define _STANDALONE to get standard <time.h>



Hellon

On Thu, Apr 18, 2019 at 09:27:51AM +0200, Martin Husemann wrote:
> On Wed, Apr 17, 2019 at 08:27:02PM +0200, tlaronde%polynum.com@localhost wrote:
> > In order to have only standard definitions in <time.h>, I have to 
> > define not standard macro _STANDALONE due to inclusion of <sys/time.h>
> > (that does not only contain declarations but definitions of functions?
> > In a header?).
> 
> It only includes <sys/time.h> if _POSIX_C_SOURCE, _XOPEN_SOURCE or
> _NETBSD_SOURCE is defined.
> 
> > Shouldn't it be the reverse, not:
> > 
> > #if !defined(_STANDALONE)
> 
> No, the parts protected by that #ifdef should not be available in a standalone
> environment (that is for example bootloaders).
> 
> You did not describe what exact problem you are hitting. Therere are various
> standards in several versions that describe different things that <time.h>
> should export - maybe one of the ifdefs is wrong, but it is not the 
> _STANDALONE part directly.
> 

Got it. The problem is that time.h is included in a block:

{
#include <time.h>
time_t cal;
...
}

as long as there are only declarations, this is not a problem. But with
definitions, there are problems.

So my solution is to put the include header at top, as usual (I wanted
to put the declarations nearer the only one stop where they are used).

As far as I understand, the POSIX standard talks only about declarations
of functions. Not definitions.

It seems that _NETBSD_SOURCE is always defined when sys/featuretest.h
is included:

sys/featuretest.h:68

#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
    !defined(_XOPEN_SOURCE) && !defined(_NETBSD_SOURCE)
#define _NETBSD_SOURCE 1
#endif

and this header is included almost everywhere.

Best regards,
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                       http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index