[comp.windows.x] time.h

wing@WINTERMUTE.FULLERTON.EDU (Michael Wing) (11/19/90)

I am tring to include time.h in a program running under motif.  When I compile
I get a message saying that line 6 of time.h is redeclaring tm.  It looks like
the include for the X11/intrinsic.h is declaring its own tm.  Is this a major
bug or is there some fix for this.  We should be able to include standard 
packages like time.h without any problems.
Any help in this area would be much appreciated.

Thanks in advance
Mike Wing
wing@wintermute.fullerton.edu

converse@EXPO.LCS.MIT.EDU (11/20/90)

> I am tring to include time.h in a program running under motif.  When I compile
> I get a message saying that line 6 of time.h is redeclaring tm.  It looks like
> the include for the X11/intrinsic.h is declaring its own tm. 

From here it looks like Intrinsic.h includes Xos.h which includes sys/time.h.

> Is this a major bug or is there some fix for this. 

Probably no to both, but I don't know what Xt software or o.s. you are running.

> We should be able to include standard 
> packages like time.h without any problems.

Agreed.  Header files often contain the definition of a preprocessor symbol
which can be used to prevent the error of including a header file more than
once, by wrapping the include.  

#ifndef __XTIME__
#include <sys/time.h>
#endif

But it is not clear to me whether these symbols are defined by any standard.

clive@x.co.uk (Clive Feather) (11/28/90)

In article <9011191648.AA22040@excess.lcs.mit.edu> converse@EXPO.LCS.MIT.EDU writes:
> Header files often contain the definition of a preprocessor symbol
> which can be used to prevent the error of including a header file more than
> once, by wrapping the include.  
>
> #ifndef __XTIME__
> #include <sys/time.h>
> #endif
>
> But it is not clear to me whether these symbols are defined by any standard.

There is no standard naming these includes. POSIX (IS 9945-1 / IEEE 1003.1)
and ANSI C (DIS 9989 / ANSI X3.159) both require that all the header files
they define must be idempotent - i.e. including them a second or subsequent
time must have no effect. The easiest way to do this is with such a symbol in
the include file:

  #ifndef __XTIME__
  #define __XTIME__
  [contents of sys/time.h]
  #endif /* __XTIME__ */
  /* DON'T put anything after this endif */

In addition, ANSI C says that symbols beginning with double underscore or with
underscore followed by a capital letter are reserved for the implementation in
this context (this can include special treatment by the compiler), so you
should take care in doing this yourself. Note that this rule makes the MIT
distribution non-conformant if used standalone.
-- 
Clive D.W. Feather     | IXI Limited         | If you lie to the compiler,
clive@x.co.uk          | 62-74 Burleigh St.  | it will get its revenge.
Phone: +44 223 462 131 | Cambridge   CB1 1OJ |   - Henry Spencer
(USA: 1 800 XDESK 57)  | United Kingdom      |