Pattern-less function names. For
Queue.h
, rather see function named obviously make sense together likeQueue_Init()
,Queue_GetSize()
thanqueueInit()
,getQueueSize()
, etc.Comments with
#
preprocessing may not be portable// #endif /* QUEUE_H_INCLUDED */ /* QUEUE_H_INCLUDED */ #endif
There is notno need for a
head
andtail
. Alternative, only storetail
and have the tail point to the head of the list. End of list detected whenp->next == tail->next
. This makes your head node one filedfield smaller. Important if code uses lots of queues.Unclear why code uses
int
for the queue size type. A signed type is not needed (could useunsigned
) and on a system wheresize_t
could be much wider thanint
, a queue size likesize_t
is more prudent. Robust code would check for a queue exceed the max value ofsize
inenqueue()
.Good use of
size_t
formemSize
. Good error checking formalloc()
. Good to have test case. IMO, a commented sample usage in the*.h
file is nice. ; the*.h
being the public interface to your good code.Pedantic: Robust would check for
memSize==0
inqueueInit()
as that negates the correctness of themalloc()
checks which should beif(newNode->data == NULL && q->memSize > 0)
.A little documentation goes a long way. suggest a line or two of comment preceding each function declaration in
Queue.h
.Functions like
queuePeek(Queue *q, void *data)
that do not alter*q
should be declaredqueuePeek(const Queue *q, void *data)
. This self documents the unchanging nature ofq
in the function to users and allows some optimizations a compiler may not otherwise employ. It is a check on the implementation of the function too.For completeness, suggest
q->memSize = 0
inclearQueue()
.Change
#include
order. Put"Queue.h"
first as a check thatQueue.h
does not depend on the 3<*.h>
include files - unless that.h
file is coded inQueue.h
.#include "Queue.h" #include <stdio.h> #include <stdlib.h> #include <string.h> // #include "Queue.h"
Indicate failure. If
void dequeue(Queue *q, void *data)
does not have anything in the queue to copy todata
, there is no indication of that here. Perhaps returntrue/false
indicating success. Same forqueuePeek()
.For debugging, zero filling memory before
free()
I have found useful. Errant code tends to fail faster with a 0 pointer/data than with its original data still potentially intact. Faster failing code is easier to debug. YMMV.Opinion: Storing the queue size is of dubious value, unless of course that is the reason for the
queue
type - one with a quicksize
report. Alternative, drop thesize
field and calculatedcalculate when needed. More often, I have found thenthe need forbool Queue_IsEmpty(const Queue *q)
sufficient than needing a quicksize
and prefer to drop the ever presentsize
field.
Pattern-less function names. For
Queue.h
, rather see function named obviously make sense together likeQueue_Init()
,Queue_GetSize()
thanqueueInit()
,getQueueSize()
, etc.Comments with
#
preprocessing may not be portable// #endif /* QUEUE_H_INCLUDED */ /* QUEUE_H_INCLUDED */ #endif
There is not need for a
head
andtail
. Alternative, only storetail
and have the tail point to the head of the list. End of list detected whenp->next == tail->next
. This makes your head node one filed smaller. Important if code uses lots of queues.Unclear why code uses
int
for the queue size type. A signed type is not needed (could useunsigned
) and on a system wheresize_t
could be much wider thanint
, a queue size likesize_t
is more prudent. Robust code would check for a queue exceed the max value ofsize
inenqueue()
.Good use of
size_t
formemSize
. Good error checking formalloc()
. Good to have test case. IMO, a commented sample usage in the*.h
file is nice. ; the*.h
being the public interface to your good code.Pedantic: Robust would check for
memSize==0
inqueueInit()
as that negates the correctness of themalloc()
checks which should beif(newNode == NULL && q->memSize > 0)
.A little documentation goes a long way. suggest a line or two of comment preceding each function declaration in
Queue.h
.Functions like
queuePeek(Queue *q, void *data)
that do not alter*q
should be declaredqueuePeek(const Queue *q, void *data)
. This self documents the unchanging nature ofq
in the function to users and allows some optimizations a compiler may not otherwise employ. It is a check on the implementation of the function too.For completeness, suggest
q->memSize = 0
inclearQueue()
.Change
#include
order. Put"Queue.h"
first as a check thatQueue.h
does not depend on the 3<*.h>
include files - unless that.h
file is coded inQueue.h
.#include "Queue.h" #include <stdio.h> #include <stdlib.h> #include <string.h> // #include "Queue.h"
Indicate failure. If
void dequeue(Queue *q, void *data)
does not have anything in the queue to copy todata
, there is no indication of that here. Perhaps returntrue/false
indicating success. Same forqueuePeek()
.For debugging, zero filling memory before
free()
I have found useful. Errant code tends to fail faster with a 0 pointer/data than with its original data still potentially intact. Faster failing code is easier to debug. YMMV.Opinion: Storing the queue size is of dubious value, unless of course that is the reason for the
queue
type - one with a quicksize
report. Alternative, drop thesize
field and calculated when needed. More often, I have found then need forbool Queue_IsEmpty(const Queue *q)
sufficient than needing a quicksize
and prefer to drop the ever presentsize
field.
Pattern-less function names. For
Queue.h
, rather see function named obviously make sense together likeQueue_Init()
,Queue_GetSize()
thanqueueInit()
,getQueueSize()
, etc.Comments with
#
preprocessing may not be portable// #endif /* QUEUE_H_INCLUDED */ #endif
There is no need for a
head
andtail
. Alternative, only storetail
and have the tail point to the head of the list. End of list detected whenp->next == tail->next
. This makes your head node one field smaller. Important if code uses lots of queues.Unclear why code uses
int
for the queue size type. A signed type is not needed (could useunsigned
) and on a system wheresize_t
could be much wider thanint
, a queue size likesize_t
is more prudent. Robust code would check for a queue exceed the max value ofsize
inenqueue()
.Good use of
size_t
formemSize
. Good error checking formalloc()
. Good to have test case. IMO, a commented sample usage in the*.h
file is nice. ; the*.h
being the public interface to your good code.Pedantic: Robust would check for
memSize==0
inqueueInit()
as that negates the correctness of themalloc()
checks which should beif(newNode->data == NULL && q->memSize > 0)
.A little documentation goes a long way. suggest a line or two of comment preceding each function declaration in
Queue.h
.Functions like
queuePeek(Queue *q, void *data)
that do not alter*q
should be declaredqueuePeek(const Queue *q, void *data)
. This self documents the unchanging nature ofq
in the function to users and allows some optimizations a compiler may not otherwise employ. It is a check on the implementation of the function too.For completeness, suggest
q->memSize = 0
inclearQueue()
.Change
#include
order. Put"Queue.h"
first as a check thatQueue.h
does not depend on the 3<*.h>
include files - unless that.h
file is coded inQueue.h
.#include "Queue.h" #include <stdio.h> #include <stdlib.h> #include <string.h> // #include "Queue.h"
Indicate failure. If
void dequeue(Queue *q, void *data)
does not have anything in the queue to copy todata
, there is no indication of that here. Perhaps returntrue/false
indicating success. Same forqueuePeek()
.For debugging, zero filling memory before
free()
I have found useful. Errant code tends to fail faster with a 0 pointer/data than with its original data still potentially intact. Faster failing code is easier to debug. YMMV.Opinion: Storing the queue size is of dubious value, unless of course that is the reason for the
queue
type - one with a quicksize
report. Alternative, drop thesize
field and calculate when needed. More often, I have found the need forbool Queue_IsEmpty(const Queue *q)
sufficient than needing a quicksize
and prefer to drop the ever presentsize
field.
Pattern-less function names. For
Queue.h
, rather see function named obviously make sense together likeQueue_Init()
,Queue_GetSize()
thanqueueInit()
,getQueueSize()
, etc.Comments with
#
preprocessing may not be portable// #endif /* QUEUE_H_INCLUDED */ /* QUEUE_H_INCLUDED */ #endif
There is not need for a
head
andtail
. Alternative, only storetail
and have the tail point to the head of the list. End of list detected whenp->next == tail->next
. This makes your head node one filed smaller. Important if code uses lots of queues.Unclear why code uses
int
for the queue size type. A signed type is not needed (could useunsigned
) and on a system wheresize_t
could be much wider thanint
, a queue size likesize_t
is more prudent. Robust code would check for a queue exceed the max value ofsize
inenqueue()
.Good use of
size_t
formemSize
. Good error checking formalloc()
. Good to have test case. IMO, a commented sample usage in the*.h
file is nice. ; the*.h
being the public interface to your good code.Pedantic: Robust would check for
memSize==0
inqueueInit()
as that negates the correctness of themalloc()
checks which should beif(newNode == NULL && q->memSize > 0)
.A little documentation goes a long way. suggest a line or two of comment preceding each function declaration in
Queue.h
.Functions like
queuePeek(Queue *q, void *data)
that do not alter*q
should be declaredqueuePeek(const Queue *q, void *data)
. This self documents the unchanging nature ofq
in the function to users and allows some optimizations a compiler may not otherwise employ. It is a check on the implementation of the function too.For completeness, suggest
q->memSize = 0
inclearQueue()
.Change
#include
order. Put"Queue.h"
first as a check thatQueue.h
does not depend on the 3<*.h>
include files - unless that.h
file is coded inQueue.h
.#include "Queue.h" #include <stdio.h> #include <stdlib.h> #include <string.h> // #include "Queue.h"
Indicate failure. If
void dequeue(Queue *q, void *data)
does not have anything in the queue to copy todata
, there is no indication of that here. Perhaps returntrue/false
indicating success. Same forqueuePeek()
.For debugging, zero filling memory before
free()
I have found useful. Errant code tends to fail faster with a 0 pointer/data than with its original data still potentially intact. Faster failing code is easier to debug. YMMV.Opinion: Storing the queue size is of dubious value, unless of course that is the reason for the
queue
type - one with a quicksize
report. Alternative, drop thesize
field and calculated when needed. More often, I have found then need forbool Queue_IsEmpty(const Queue *q)
sufficient than needing a quicksize
and prefer to drop the ever presentsize
field.
Pattern-less function names. For
Queue.h
, rather see function named obviously make sense together likeQueue_Init()
,Queue_GetSize()
thanqueueInit()
,getQueueSize()
, etc.Comments with
#
preprocessing may not be portable// #endif /* QUEUE_H_INCLUDED */ /* QUEUE_H_INCLUDED */ #endif
There is not need for a
head
andtail
. Alternative, only storetail
and have the tail point to the head of the list. End of list detected whenp->next == tail->next
. This makes your head node one filed smaller. Important if code uses lots of queues.Unclear why code uses
int
for the queue size type. A signed type is not needed (could useunsigned
) and on a system wheresize_t
could be much wider thanint
, a queue size likesize_t
is more prudent. Robust code would check for a queue exceed the max value ofsize
inenqueue()
.Good use of
size_t
formemSize
. Good error checking formalloc()
. Good to have test case. IMO, a commented sample usage in the*.h
file is nice. ; the*.h
being the public interface to your good code.Pedantic: Robust would check for
memSize==0
inqueueInit()
as that negates the correctness of themalloc()
checks which should beif(newNode == NULL && q->memSize > 0)
.A little documentation goes a long way. suggest a line or two of comment preceding each function declaration in
Queue.h
.Functions like
queuePeek(Queue *q, void *data)
that do not alter*q
should be declaredqueuePeek(const Queue *q, void *data)
. This self documents the unchanging nature ofq
in the function to users and allows some optimizations a compiler may not otherwise employ. It is a check on the implementation of the function too.For completeness, suggest
q->memSize = 0
inclearQueue()
.Change
#include
order. Put"Queue.h"
first as a check thatQueue.h
does not depend on the 3<*.h>
include files - unless that.h
file is coded inQueue.h
.#include "Queue.h" #include <stdio.h> #include <stdlib.h> #include <string.h> // #include "Queue.h"
Indicate failure. If
void dequeue(Queue *q, void *data)
does not have anything in the queue to copy todata
, there is no indication of that here. Perhaps returntrue/false
indicating success. Same forqueuePeek()
.For debugging, zero filling memory before
free()
I have found useful. Errant code tends to fail faster with a 0 pointer/data than with its original data still potentially intact. Faster failing code is easier to debug. YMMV.
Pattern-less function names. For
Queue.h
, rather see function named obviously make sense together likeQueue_Init()
,Queue_GetSize()
thanqueueInit()
,getQueueSize()
, etc.Comments with
#
preprocessing may not be portable// #endif /* QUEUE_H_INCLUDED */ /* QUEUE_H_INCLUDED */ #endif
There is not need for a
head
andtail
. Alternative, only storetail
and have the tail point to the head of the list. End of list detected whenp->next == tail->next
. This makes your head node one filed smaller. Important if code uses lots of queues.Unclear why code uses
int
for the queue size type. A signed type is not needed (could useunsigned
) and on a system wheresize_t
could be much wider thanint
, a queue size likesize_t
is more prudent. Robust code would check for a queue exceed the max value ofsize
inenqueue()
.Good use of
size_t
formemSize
. Good error checking formalloc()
. Good to have test case. IMO, a commented sample usage in the*.h
file is nice. ; the*.h
being the public interface to your good code.Pedantic: Robust would check for
memSize==0
inqueueInit()
as that negates the correctness of themalloc()
checks which should beif(newNode == NULL && q->memSize > 0)
.A little documentation goes a long way. suggest a line or two of comment preceding each function declaration in
Queue.h
.Functions like
queuePeek(Queue *q, void *data)
that do not alter*q
should be declaredqueuePeek(const Queue *q, void *data)
. This self documents the unchanging nature ofq
in the function to users and allows some optimizations a compiler may not otherwise employ. It is a check on the implementation of the function too.For completeness, suggest
q->memSize = 0
inclearQueue()
.Change
#include
order. Put"Queue.h"
first as a check thatQueue.h
does not depend on the 3<*.h>
include files - unless that.h
file is coded inQueue.h
.#include "Queue.h" #include <stdio.h> #include <stdlib.h> #include <string.h> // #include "Queue.h"
Indicate failure. If
void dequeue(Queue *q, void *data)
does not have anything in the queue to copy todata
, there is no indication of that here. Perhaps returntrue/false
indicating success. Same forqueuePeek()
.For debugging, zero filling memory before
free()
I have found useful. Errant code tends to fail faster with a 0 pointer/data than with its original data still potentially intact. Faster failing code is easier to debug. YMMV.Opinion: Storing the queue size is of dubious value, unless of course that is the reason for the
queue
type - one with a quicksize
report. Alternative, drop thesize
field and calculated when needed. More often, I have found then need forbool Queue_IsEmpty(const Queue *q)
sufficient than needing a quicksize
and prefer to drop the ever presentsize
field.
Pattern-less function names. For
Queue.h
, rather see function named obviously make sense together likeQueue_Init()
,Queue_GetSize()
thanqueueInit()
,getQueueSize()
, etc.Comments with
#
preprocessing may not be portable// #endif /* QUEUE_H_INCLUDED */ /* QUEUE_H_INCLUDED */ #endif
There is not need for a
head
andtail
. Alternative, only storetail
and have the tail point to the head of the list. End of list detected whenp->next == tail->next
. This makes your head node one filed smaller. Important if code uses lots of queues.Unclear why code uses
int
for the queue size type. A signed type is not needed (could useunsigned
) and on a system wheresize_t
could be much wider thanint
, a queue size likesize_t
is more prudent. Robust code would check for a queue exceed the max value ofsize
inenqueue()
.Good use of
size_t
formemSize
. Good error checking formalloc()
. Good to have test case. IMO, a commented sample usage in the*.h
file is nice. ; the*.h
being the public interface to your good code.Pedantic: Robust would check for
memSize==0
inqueueInit()
as that negates the correctness of themalloc()
checks which should beif(newNode == NULL && q->memSize > 0)
.A little documentation goes a long way. suggest a line or two of comment preceding each function declaration in
Queue.h
.Functions like
queuePeek(Queue *q, void *data)
that do not alter*q
should be declaredqueuePeek(const Queue *q, void *data)
. This self documents the unchanging nature ofq
in the function to users and allows some optimizations a compiler may not otherwise employ. It is a check on the implementation of the function too.For completeness, suggest
q->memSize = 0
inclearQueue()
.Change
#include
order. Put"Queue.h"
first as a check thatQueue.h
does not depend on the 3<*.h>
include files - unless that.h
file is coded inQueue.h
.#include "Queue.h" #include <stdio.h> #include <stdlib.h> #include <string.h> // #include "Queue.h"
Indicate failure. If
void dequeue(Queue *q, void *data)
does not have anything in the queue to copy todata
, there is no indication of that here. Perhaps returntrue/false
indicating success. Same forqueuePeek()
.For debugging, zero filling memory before
free()
I have found useful. Errant code tends to fail faster with a 0 pointer/data than with its original data still potentially intact. Faster failing code is easier to debug. YMMV.