Path: chuka.playstation.co.uk!scea!peter_alau@playstation.sony.com From: "Antony Arciuolo" Newsgroups: scee.yaroze.programming.2d_graphics Subject: A simple Queue Date: Wed, 23 Sep 1998 17:40:28 -0400 Organization: SCEA News Server Lines: 221 Message-ID: <6ubp2u$1mg5@scea> NNTP-Posting-Host: aarciuol.pc.trincoll.edu X-Newsreader: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 I'm trying to make a Queue, that's all, but when I typedef the type of the Queue (implemented as an array) the system freezes. Shorts work fine, chars work fine, but I will be using this Queue for long pointers, and it just isn't working. Here is Queue.h: #ifndef QUEUE_H #define QUEUE_H // INCLUDES ------------------------------------------------- #include #include // DEFINITIONS ---------------------------------------------- #define QUEUE_DEBUG (1) #define QUEUE_RUN_MAIN (0) #define QUEUE_SIZEOF (10) #define QUEUE_OVERHEAD ( 3) #define QUEUE_HEAD (QUEUE_SIZEOF) #define QUEUE_TAIL (QUEUE_SIZEOF + 1) #define QUEUE_COUNTER (QUEUE_SIZEOF + 2) #define QUEUE_NULL (-1) typedef long QUEUE_DataType; typedef QUEUE_DataType QUEUE[QUEUE_SIZEOF + QUEUE_OVERHEAD]; // PROTOTYPES ----------------------------------------------- void QUEUE_Init(QUEUE *q); void QUEUE_Push(QUEUE *q, QUEUE_DataType item); QUEUE_DataType QUEUE_Read(QUEUE *q); QUEUE_DataType QUEUE_Pop(QUEUE *q); short QUEUE_IsEmpty(QUEUE *q); #if (QUEUE_DEBUG) void QTest(void); void QUEUE_Dump(QUEUE *q); #endif Here is Queue.c: #include "Queue.h" void QUEUE_Init(QUEUE *q) { short i; for (i = 0; i < QUEUE_SIZEOF; i++) { #if (QUEUE_DEBUG) printf("Init'ing %d to %d\n", i, QUEUE_NULL); #endif *q[i] = QUEUE_NULL; #if (QUEUE_DEBUG) printf("*q[%d] is %d\n", i, *q[i]); #endif } *q[QUEUE_HEAD] = 0; *q[QUEUE_TAIL] = 0; *q[QUEUE_COUNTER] = 0; } void QUEUE_Push(QUEUE *q, QUEUE_DataType item) { short tail; tail = (short)(*q[QUEUE_TAIL]); #if (QUEUE_DEBUG) printf("QPush(%p, %d): T:%d\n", q, item, tail); #endif if (*q[QUEUE_COUNTER] < QUEUE_SIZEOF) { if (*q[QUEUE_COUNTER] != 0) *q[QUEUE_TAIL] = (*q[QUEUE_TAIL] + 1) % QUEUE_SIZEOF; *q[*q[QUEUE_TAIL]] = item; *q[QUEUE_COUNTER] = *q[QUEUE_COUNTER] + 1; } else printf("QPush Queue Full! (%p) item: %d\n", q, item); } QUEUE_DataType QUEUE_Read(QUEUE *q) { #if (QUEUE_DEBUG) printf("QRead(%p): H:%d item: %d\n", q, *q[QUEUE_HEAD], *q[*q[QUEUE_HEAD]]); #endif return (*q[*q[QUEUE_HEAD]]); } QUEUE_DataType QUEUE_Pop(QUEUE *q) { QUEUE_DataType x; #if (QUEUE_DEBUG) printf("QPop(%p): H:%d item: %d\n", q, *q[QUEUE_HEAD], *q[*q[QUEUE_HEAD]]); #endif if (*q[QUEUE_COUNTER] > 0) { x = *q[*q[QUEUE_HEAD]]; *q[QUEUE_HEAD] = (*q[QUEUE_HEAD] + 1) % QUEUE_SIZEOF; *q[QUEUE_COUNTER] = *q[QUEUE_COUNTER] - 1; return x; } else { printf("QPop Queue Empty! (%p)\n", q); return (QUEUE_NULL); } } short QUEUE_IsEmpty(QUEUE *q) { return (!(*q[QUEUE_COUNTER])); } #if (QUEUE_DEBUG) void QUEUE_Dump(QUEUE *q) { short i; printf("Queue %p:\n", q); for (i = 0; i < (QUEUE_SIZEOF + QUEUE_OVERHEAD); i++) { printf("%d: %d, ", i, *(q[i])); } printf("\n\n"); } void QTest(void) { QUEUE q; short i; QUEUE_Init(&q); if (QUEUE_IsEmpty(&q)) printf("1. Queue is Empty!\n"); for (i = 0; i < QUEUE_SIZEOF; i++) QUEUE_Push(&q, i); if (QUEUE_IsEmpty(&q)) printf("2. Queue is Empty!\n"); QUEUE_Push(&q, 12); for (i = 0; i < QUEUE_SIZEOF; i++) printf("Pop item %d: %d\n" , i, QUEUE_Pop(&q)); if (QUEUE_IsEmpty(&q)) printf("3. Queue is Empty!\n"); QUEUE_Pop(&q); QUEUE_Dump(&q); } #endif #if (QUEUE_RUN_MAIN) void main(void) { QUEUE q; short i; QUEUE_Init(&q); if (QUEUE_IsEmpty(&q)) printf("1. Queue is Empty!\n"); for (i = 0; i < QUEUE_SIZEOF; i++) QUEUE_Push(&q, i); if (QUEUE_IsEmpty(&q)) printf("2. Queue is Empty!\n"); QUEUE_Push(&q, 12); for (i = 0; i < QUEUE_SIZEOF; i++) printf("Pop item %d: %d\n" , i, QUEUE_Pop(&q)); if (QUEUE_IsEmpty(&q)) printf("3. Queue is Empty!\n"); QUEUE_Pop(&q); QUEUE_Dump(&q); } #endif #endif Can anyone help? Please! I am testing this in my main by this method: void main(void) { QTest(); return; // I just want to test the Queue ... The rest of my code ... } - Tony