Alternate: use integer truncation of division. Add 1 less than the divisor, then divide.
// location of CHAR_BIT
#include <limits.h>
#define MINUTES_PER_DAY (24u * 60)
#define UCHAR_PER_DAY ((MINUTES_PER_DAY + CHAR_BIT - 1)/ CHAR_BIT)
UCHAR minutesOfDay[UCHAR_PER_DAY];
This assumes UCHAR
is unsigned char
. To avoid that assumption:
#define UCHAR_PER_DAY ((MINUTES_PER_DAY + CHAR_BIT*sizeof(UCHAR) - 1) / \
(CHAR_BIT*sizeof(UCHAR)))
UCHAR minutesOfDay[UCHAR_PER_DAY];
Pedantically this is not correct had we needed some other unsigned integer type like unsigned
or unsigned long
. unsigned char
, assuming that what UCHAR
is, cannot have padding bits. Esoteric platforms could have padding bits with wider unsigned types.