C预编译宏
/* ============================================================================ Name : c_test001.c Author : jiftle Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \ + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0')) #define MONTH (__DATE__ [2] == 'n' ? 0 \ : __DATE__ [2] == 'b' ? 1 \ : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \ : __DATE__ [2] == 'y' ? 4 \ : __DATE__ [2] == 'n' ? 5 \ : __DATE__ [2] == 'l' ? 6 \ : __DATE__ [2] == 'g' ? 7 \ : __DATE__ [2] == 'p' ? 8 \ : __DATE__ [2] == 't' ? 9 \ : __DATE__ [2] == 'v' ? 10 : 11) #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \ + (__DATE__ [5] - '0')) #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY) int main(void) { puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ printf("%s\n","----------------------------------"); printf("%-30s = %10d\n","__STDC_HOSTED__",__STDC_HOSTED__); printf("%-30s = %10d\n","__STDC_VERSION__",__STDC_VERSION__); printf("%-30s = %10d\n","__STDC__",__STDC__); printf("%-30s = %10s\n","__DATE__",__DATE__); printf("%-30s = %10s\n","__TIME__",__TIME__); printf("build time: %d-%02d-%02d %s\n",YEAR, MONTH + 1, DAY,__TIME__); return EXIT_SUCCESS; }
linux下,gcc 运行结果:
---------------------------------- __STDC_HOSTED__ = 1 __STDC_VERSION__ = 201112 __STDC__ = 1 __DATE__ = Jun 22 2017 __TIME__ = 11:08:59 build time: 2017-01-22 11:08:59