From 5d376a9592e733770bc68419298ff1d085dd1d88 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 24 May 2014 10:29:54 +0800 Subject: [PATCH] use typedef --- include/r3_queue.h | 13 +++++++++---- tests/check_queue.c | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/r3_queue.h b/include/r3_queue.h index cfac28d..a5af6f5 100644 --- a/include/r3_queue.h +++ b/include/r3_queue.h @@ -13,16 +13,21 @@ #include #include +struct _queue; +struct _queue_node; +typedef struct _queue_node queue_node; +typedef struct _queue queue; + struct _queue_node { void *data; - struct _queue_node * next; + queue * next; }; -typedef struct _queue_node queue_node; +// typedef struct _queue_node queue_node; -typedef struct { +struct _queue { queue_node * first; queue_node * last; -} queue; +}; // create and return the queue queue * queue_new(void); diff --git a/tests/check_queue.c b/tests/check_queue.c index ee2f138..bf0d4b4 100644 --- a/tests/check_queue.c +++ b/tests/check_queue.c @@ -59,12 +59,12 @@ START_TEST (test_queue) { queue * q = queue_new(); - for (short i = 0 ; i < 100 ; i++ ) { + for (int i = 0 ; i < 100 ; i++ ) { queue_push(q, (void*) i); } - for (short i = 0 ; i < 100 ; i++ ) { - short v = (short) queue_pop(q); + for (int i = 0 ; i < 100 ; i++ ) { + int v = (int) queue_pop(q); ck_assert_int_eq(i, v); } queue_free(q);