瀏覽代碼

refactor EVENS with modulo 2

Francois Perrad 10 年之前
父節點
當前提交
74d55a0e34
共有 2 個文件被更改,包括 3 次插入3 次删除
  1. 2 2
      tests/test36.c
  2. 1 1
      tests/test37.c

+ 2 - 2
tests/test36.c

@@ -8,10 +8,10 @@ typedef struct {
     UT_hash_handle ah;
 } example_user_t;
 
-#define EVENS(x) (((x)->id & 1) == 0)
+#define EVENS(x) (((x)->id % 2) == 0)
 static int evens(void *userv) {
   example_user_t *user = (example_user_t*)userv;
-  return ((user->id & 1) ? 0 : 1);
+  return ((user->id % 2) ? 0 : 1);
 }
 
 static int idcmp(void *_a, void *_b) {

+ 1 - 1
tests/test37.c

@@ -8,7 +8,7 @@ typedef struct {
     UT_hash_handle ah;
 } example_user_t;
 
-#define EVENS(x) ((((example_user_t*)(x))->id & 1) == 0)
+#define EVENS(x) ((((example_user_t*)(x))->id % 2) == 0)
 
 static int idcmp(void *_a, void *_b) {
   example_user_t *a = (example_user_t*)_a;