# HG changeset patch # User Thinker K.F. Li # Date 1219511938 -28800 # Node ID c3c41f88e776b96930c937306f7cc75276cfb6fc # Parent 3f619ae03678371e2872a6b405b5950030c28ac9 - diff -r 3f619ae03678 -r c3c41f88e776 examples/calculator/main.c --- a/examples/calculator/main.c Sun Aug 24 00:18:59 2008 +0800 +++ b/examples/calculator/main.c Sun Aug 24 01:18:58 2008 +0800 @@ -47,10 +47,9 @@ r = v1 * v2; break; case '/': + r = v1; if(v2) - r = v1 / v2; - else - r = v1; + r /= v2; break; case 'n': r = v2; @@ -161,7 +160,7 @@ for(i = 0; i < 16; i++) { off = tgt_list[i].off; - coord = *(coord_t **)((void *)calculator_scr + off); + coord = OFF2TYPE(calculator_scr, off, coord_t *); subject = coord_get_mouse_event(coord); subject_add_observer(factory, subject, buttons_handler, ex_rt); } diff -r 3f619ae03678 -r c3c41f88e776 src/tools.h --- a/src/tools.h Sun Aug 24 00:18:59 2008 +0800 +++ b/src/tools.h Sun Aug 24 01:18:58 2008 +0800 @@ -45,7 +45,7 @@ (elm)->field = follow; \ } while(0) #define STAILQ_REMOVE(q, type, field, elm) \ - do { \ +~ do { \ if((elm) == (q).head) { \ (q).head = (elm)->field; \ if((q).head == NULL) \ @@ -68,5 +68,6 @@ #define OFFSET(type, mem) (((void *)&((type *)NULL)->mem) - NULL) #define MEM2OBJ(var, type, mem) ((type *)((void *)var - OFFSET(type, mem))) +#define OFF2TYPE(obj, off, type) (*(type *)((void *)(obj) + (off))) #endif /* __TOOLS_H_ */