Re: Creating more generic data structures



On 10 Aug, 15:49, Andrea Crotti <andrea.crott...@xxxxxxxxx> wrote:

In our project my groupmate wanted to have a generic queue (which we
don't really need since it's used once)

I'm half sympathetic with him. It's a useful tool to have around. But
if you spend too much time writing generic stuff you don't get
anything done. Of course the question is "why is he implementing it on
*this* project". If his queue is so brilliant why didn't he implement
it on a previous project? Or does he implement a generic queue on
every project...

and so he ended up with a enormous ugly macro.

not sure why...

He said it's the only way to accomplish having different data types
inside a queue in C, is that true?

no, complete rubbish. There are masses of ways to implement queues.
Cyclic buffers, linked lists. With linked lists the pointers can be
embedded in the data or you have a carrier node

struct Node
{
struct Node *next;
void *data;
};

To make it generic you can wite it in terms of type T which is defined
by a typedef

typedef double T;

Harder to have multiple types of queue.

You could code generate the code when you needed it.

Look up past posts for Jacob Navia's ideas on gneric data structures.
(I forget the details but he used tables of fucntion pointers and it
sounded a lot less messy than what you've got).

Would not work just creating a module which takes the size and uses some
pointers to void to obtain the same result?
Something as below (modified of course) could not work as well?
.



Relevant Pages

  • Re: Creating more generic data structures
    ... Cyclic buffers, linked lists. ... struct Node *next; ... typedef double T; ... Here is the queue: ...
    (comp.lang.c)
  • Re: Queue in C99?
    ... queue and send them off to the server. ... To add a message to be logged, the first thread acquires the mutex, ... struct node* next; ... queue_push(struct queue* const self, ...
    (comp.lang.c)
  • Re: __asm__ cmpxchg8b/cmpxchg16b
    ... struct mpmcq* const self, ... struct node* prev; ... After #1 the head points at the new node, but the last node in the queue doesnt join up yet. ... So if a thread stalled between those two lines, consumers wouldnt be able to get past that break, new items could be added, but they'd be inaccessable to consumers until the stalled thread completed the join? ...
    (comp.programming.threads)
  • Re: level order traversal of binary tree
    ... This queue is allocated in automatic storage, ... This declaration declares only front. ... number of nodes in the tree. ... of the null pointers in the leaves. ...
    (comp.lang.c)
  • Re: copying an array of pointers to structures
    ... I don't recommend casting the return value of malloc: ... > and I then want to copy whats in Graph (the pointers) in the Queue: ...
    (comp.lang.c)