You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Gregory A Lundberg <lu...@vr.net> on 1997/10/28 15:14:58 UTC

Standard C: __DATE__ and __TIME__

In answer to earlier questions concerning Standard C ...

>From ANSI/ISO 9899-1990, American National Standard for Programming
Languages - C

----

6.8.8 Predefined macro names

   The following names shall be defined by the implementation:

__LINE__ The line number of the current source line (a decimal constant).

__FILE__ The presumed name of the source file (a character string
         literal).

__DATE__ The date of translation of the source file (a character string
         literal of the form "Mmm dd yyyy", where the names of the months
         are the same as those generated by the asctime function, and the
         first character of dd is a space character if the value is less
         than 10).  If the date of translation is not available, an
         implementation-defined valid date shall be supplied. 

__TIME__ The time of translation of the source file (a character string
         literal of the form "hh:mm:ss" as in the time generated by the
         asctime function).  If the time of translation is not available,
         an implementation-defined valid time shall be supplied. 

__STDC__ The decimal constant 1, intended to indicate a conforming
         implementation.

   The values of the predefined macros (except for __LINE__ and __FILE__) 
remain constant throughout the translation unit. 

   None of these macro names, nor the identifier defined, shall be the
subject of a #define or a #undef preprocessing directive.  All predefined
macro names shall begin with a leading underscore followed by an uppercase
letter or a second underscore. 

Forward references: the asctime function (7.12.3.1). 

----

Annex G (informative) Portability Issues

G.2 Undefined behavior

-- One of the following identifiers is the subject of a #define or #undef
   preprocessing directive: defined, __LINE__, __FILE__, __DATE__,
   __TIME__, or __STDC__ (6.8.8). 

G.3 Implementation-defined behavior

G.3.13 Preprocessing directives

-- The definitions for __DATE__ and __TIME__ when respectively, the date
   and time of translation are not available (6.8.8). 

----

Remember, paragraph numbers are different between the ANSI and ISO
versions, and there may have been slight wording changes since 1990
(although I doubt it).  The working group's notes are available on the
Web if someone wants to wade through them looking for more.

The question was, "does the standard use MUST or SHOULD" .. it uses SHALL,
an imperative.  Implementations which do not provide all five of the
predfined macro names are non-standard.  Therefore the code stub given
earlier should be rewritten as: 

#if __STDC__ == 1
  #define COMPILED_ON __DATE__ " " __TIME__
#else
  #error Apache requires a conforming Standard C compiler, this one is not
#endif