add ()'s to the macros for more safety

This commit is contained in:
Dana Jansens 2003-04-06 06:16:34 +00:00
parent 6016ff8658
commit b31eb83f04

View file

@ -6,14 +6,14 @@ typedef struct Point {
int y; int y;
} Point; } Point;
#define POINT_SET(pt, nx, ny) pt.x = (nx), pt.y = (ny) #define POINT_SET(pt, nx, ny) (pt).x = (nx), (pt).y = (ny)
typedef struct Size { typedef struct Size {
int width; int width;
int height; int height;
} Size; } Size;
#define SIZE_SET(sz, w, h) sz.width = (w), sz.height = (h) #define SIZE_SET(sz, w, h) (sz).width = (w), (sz).height = (h)
typedef struct Rect { typedef struct Rect {
int x; int x;
@ -23,17 +23,19 @@ typedef struct Rect {
} Rect; } Rect;
#define RECT_SET_POINT(r, nx, ny) \ #define RECT_SET_POINT(r, nx, ny) \
r.x = (ny), r.y = (ny) (r).x = (ny), (r).y = (ny)
#define RECT_SET_SIZE(r, w, h) \ #define RECT_SET_SIZE(r, w, h) \
r.width = (w), r.height = (h) (r).width = (w), (r).height = (h)
#define RECT_SET(r, nx, ny, w, h) \ #define RECT_SET(r, nx, ny, w, h) \
r.x = (nx), r.y = (ny), r.width = (w), r.height = (h) (r).x = (nx), (r).y = (ny), (r).width = (w), (r).height = (h)
#define RECT_EQUAL(r1, r2) (r1.x == r2.x && r1.y == r2.y && \ #define RECT_EQUAL(r1, r2) ((r1).x == (r2).x && (r1).y == (r2).y && \
r1.width == r2.width && r1.height == r2.height) (r1).width == (r2).width && \
(r1).height == (r2).height)
#define RECT_CONTAINS(r, x, y) \ #define RECT_CONTAINS(r, x, y) \
(x >= r.x && x < r.x + r.width && y >= r.y && y < r.y + r.height) (x >= (r).x && x < (r).x + (r).width && \
y >= (r).y && y < (r).y + (r).height)
typedef struct Strut { typedef struct Strut {
int left; int left;
@ -43,10 +45,12 @@ typedef struct Strut {
} Strut; } Strut;
#define STRUT_SET(s, l, t, r, b) \ #define STRUT_SET(s, l, t, r, b) \
s.left = (l), s.top = (t), s.right = (r), s.bottom = (b) (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b)
#define STRUT_ADD(s1, s2) \ #define STRUT_ADD(s1, s2) \
s1.left = MAX(s1.left, s2.left), s1.right = MAX(s1.right, s2.right), \ (s1).left = MAX((s1).left, (s2).left), \
s1.top = MAX(s1.top, s2.top), s1.bottom = MAX(s1.bottom, s2.bottom) (s1).right = MAX((s1).right, (s2).right), \
(s1).top = MAX((s1).top, (s2).top), \
(s1).bottom = MAX((s1).bottom, (s2).bottom)
#endif #endif