Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ preprocessor #if with datetime

I guess this is not possible (yet) but not sure. I need to do conditional compilation based on current date. Something like:

#if (__CURRENT_YEAR < 2016)
...
#endif

I need to exclude something from project after some months and be sure that this will not be forgotten (in future releases).

like image 975
i486 Avatar asked Nov 20 '25 05:11

i486


1 Answers

In your Makefile add

CFLAGS += -DYEAR=$(shell date +%g)

Then in your C source:

#if (YEAR < 16)
....
#endif
like image 143
qrdl Avatar answered Nov 22 '25 02:11

qrdl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!