Goal is to write the shortest possible C89 and C99-compliant single-module C program which will compute and print out a single-line string whose sort order will correspond with the date given by the predefined __DATE__
macro (in other words, later dates will yield later-sorting strings). The programmer is free to arbitrarily select the mapping between dates and strings, but every entry should specify the mapping and it should be obvious that it will sort correctly (e.g. a programmer could decide to compute (day + month*73 + year*4129) and output that as a number, though it's likely that particular encoding would probably require a longer program than some others).
The program should yield identical results on any standards-compliant compiler on which 'int' is 32 bits or larger and both source and target character sets are 7-bit ASCII, and should not rely upon any implementation-defined or undefined behavior nor print any characters outside the 32-126 range except for a single newline at the end. The program should contain the following aspects indicated below (replacing «CODE» with anything desired):
♯include <stdio.h> «CODE»int main(void){«CODE»}
All output shall be produced by the printf
at the end (i.e. the correct value will be in an int
called z
). The required elements will be included in the character total for each entry.
Code should operate correctly for all future dates through Dec 31 9999
. Libraries which are standard in both C89 and C99 may be used, provided that appropriate headers are included. Note that standard date libraries may not be assumed to operate beyond the Unix limits.
Note: Code is permitted to perform Undefined Behavior if and only if the __DATE__
macro expands to a macro other than a date between Feb 11 2012
and Dec 31 9999
(expressed in that format, using C-standard abbreviated English month names Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
Note 2: For compliance with C99 standards, 'main' should return an arbitrary, but defined value, and the newline is required. The first requirement, btw, adds 7 characters to my best effort; the single new-line adds 5.
LC_ALL=C date -d "2060/02/13" date: invalid date
2060/02/13'` \$\endgroup\$$ LC_ALL=C date -d "2060/02/13" Fri Feb 13 00:00:00 CST 2060
on x86_64. \$\endgroup\$