Re: Creating more generic data structures
- From: Nick Keighley <nick_keighley_nospam@xxxxxxxxxxx>
- Date: Tue, 10 Aug 2010 08:11:39 -0700 (PDT)
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?
- Follow-Ups:
- Re: Creating more generic data structures
- From: Andrea Crotti
- Re: Creating more generic data structures
- References:
- Creating more generic data structures
- From: Andrea Crotti
- Creating more generic data structures
- Prev by Date: Re: C Test Incorrectly Uses printf() - Please Confirm
- Next by Date: Re: C Test Incorrectly Uses printf() - Please Confirm
- Previous by thread: Creating more generic data structures
- Next by thread: Re: Creating more generic data structures
- Index(es):
Relevant Pages
|