Skip to content

Instantly share code, notes, and snippets.

@camel-cdr
Last active February 19, 2022 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camel-cdr/78dca38e09ff5391beabe9c1575248f0 to your computer and use it in GitHub Desktop.
Save camel-cdr/78dca38e09ff5391beabe9c1575248f0 to your computer and use it in GitHub Desktop.
C code that is syntactically correct only on Fridays
#include <stdio.h>
#include <time.h>
static const char mon_name[12][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int
main(void)
{
static char str[] = "Mmm dd yyyy";
struct tm it = {0};
do {
mktime(&it);
sprintf(str, "%.3s %2d %4d",
mon_name[it.tm_mon],
it.tm_mday,
1900 + it.tm_year);
puts(str);
FILE *f = fopen(str, "w");
if (it.tm_wday == 5)
fputs("#define ITS_FRIDAY 1", f);
fclose(f);
++it.tm_mday;
} while (it.tm_year < 10000 - 1900);
}
#include <stdio.h>
#include __DATE__
#if !ITS_FRIDAY
:-)
#endif
int main(void)
{
puts("Hello");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment