I'm taking a class in C with a couple of friends. We're doing a project on Huffman Encoding and I am trying to understand the Rosetta stone version of the code. I think I've figured most of it out, but I don't understand a couple of variables.
typedef struct node_t {
struct node_t *left, *right;
int freq;
char c;
} *node;
struct node_t pool[256] = { { 0 } };
node qqq[255], *q = qqq - 1;
Can someone please explain to me what *node means, and what node qqq[255] is, and what *q = qqq-1 means.
The only reason I ask is I think I am making an error somewhere in my understanding because I don't really get the relationships between these pointer nodes.
The declaration:
defines the
nodetype as pointer tonode_tstructures (which appear to be typical binary search nodes). So whilepool[]is an array ofnode_tstructures,qqq[]is an array of pointers (to said structures). Now think ofqqqas a pointer to the start of some (stack reserved) bytes to hold a bunch of pointers (255*sizeof(node)or255*sizeof(struct node_t*)bytes).Then
is similar in that it defines
qas a pointer tonodes, but without reserving any bytes. Instead,qis initialized to point toqqq-1which is probably intended to mean "point tosizeof(node)beforeqqq".(While this last piece of pointer arithmetic probably works, pointing outside of
qqqis not a good idea because adding an subtracting pointers is only defined behaviour when resulting address is within defined range.)Supposedly, what follows is a loop where
qis a pre-incremented iterator traversingqqqs data.