fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. int main(void) {
  5. // using preprocessor 'trick'
  6. struct tm uniquenamewith__LINE__inthename = {0};
  7. uniquenamewith__LINE__inthename.tm_year = 2019 - 1900;
  8. uniquenamewith__LINE__inthename.tm_mon = 12 - 1;
  9. uniquenamewith__LINE__inthename.tm_mday = 18;
  10. time_t foo = mktime(&uniquenamewith__LINE__inthename);
  11.  
  12. // using compound literal
  13. time_t bar = mktime(&(struct tm){.tm_year=2019-1900, .tm_mon=12-1, .tm_mday=18});
  14.  
  15. printf("foo is %lu, bar is %lu\n", (unsigned long)foo, (unsigned long)bar);
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 4316KB
stdin
Standard input is empty
stdout
foo is 1576627200, bar is 1576627200