changeset 93:c3c41f88e776

-
author Thinker K.F. Li <thinker@branda.to>
date Sun, 24 Aug 2008 01:18:58 +0800
parents 3f619ae03678
children 57f8fecca8f3
files examples/calculator/main.c src/tools.h
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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);
     }
--- 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_ */