// a short list of popular macro defines
 
// macros to get high and low byte of an integer x
#define HIBYTE(x)   ((unsigned int)(x) >> 8)
#define LOWBYTE(x)  ((unsigned char)(x))

// years ending with 00 have to divisible by 400 to be leap year
#define ISLEAPYEAR(year)  ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))

// RGB macro red, green, blue are bytes 0 to 255
#define RGB(r,g,b) ((DWORD)(((BYTE)(r)|((WORD)(g) << 8))|(((DWORD)(BYTE)(b)) << 16))) 

// macro to swap two arguments of a specified type (here int)
#define SWAP(a,b)   { int t; t=a; a=b; b=t; }

// DOS console mode only
#define clrscr()  system("CLS")

// macros for arrays
#define ARRAYSIZE(x)  (sizeof(x)/sizeof(*(x)))
#define NELEM(x)      (sizeof(x)/sizeof(x[0]))
2
Contributors
3
Replies
5
Views
12 Years
Discussion Span
Last Post by vegaseat
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.