首页 > 代码库 > C预编译宏
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:59build time: 2017-01-22 11:08:59
C预编译宏
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。