If I want to use preprocessor instructions #defineto simplify the definition and calculation of constants and common functions, and use less RAM (as opposed to using values const). However, I'm not sure how they are resolved if many macros are used together.
I am developing my own code processing DateTime, similar to linux timestamps, but for playing with checkbox updates that are 1/60 of a second. I would rather declare the values ββchained, but I wonder if more stringent encoding will be performed.
#include <stdint.h>
typedef int64_t DateTime;
#define TICKS_PER_SEC 60L
#define SEC_PER_MIN 60L
#define MIN_PER_HR 60L
#define HRS_PER_DAY 24L
#define DAYS_PER_WEEK 7L
#define WEEKS_PER_YEAR 52L
#define TICKS_PER_MIN TICKS_PER_SEC * SEC_PER_MIN
#define TICKS_PER_HR TICKS_PER_SEC * SEC_PER_MIN * MIN_PER_HR
#define TICKS_PER_DAY TICKS_PER_SEC * SEC_PER_MIN * MIN_PER_HR * HRS_PER_DAY
#define TICKS_PER_MIN_H 3600L
#define TICKS_PER_HR_H 216000L
#define TICKS_PER_DAY_H 5184000L
#define sec(t)((t / TICKS_PER_DAY) % DAYS_PER_WEEK)
sec(t), TICKS_PER_DAY, TICKS_PER_SEC * SEC_PER_MIN * MIN_PER_HR * HRS_PER_DAY, , sec(t):
(t / 5184000L) % 7L)
:
(t / (60L * 60L * 60L * 24L)) % 7L)
? , , ?
UPDATE:
, , ,
1. :
(t / 60 * 60 * 60 * 24) != (t / (60 * 60 * 60 * 24))
2. , :
#define TICKS_PER_MIN (TICKS_PER_SEC * SEC_PER_MIN)
#define TICKS_PER_HR (TICKS_PER_SEC * SEC_PER_MIN * MIN_PER_HR)
#define TICKS_PER_DAY (TICKS_PER_SEC * SEC_PER_MIN * MIN_PER_HR * HRS_PER_DAY)