Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include "memory.h"
- #define POOL_SIZE 10
- // pool of memory
- struct record pool[POOL_SIZE];
- struct record * top=pool; // pool is constant; a pointer to the stack top.
- void init_pool() // Initialize the pool
- {
- int i;
- struct record *r=pool;
- struct record *s;
- pool[POOL_SIZE-1].next=NULL;
- for(i=1;i<POOL_SIZE;i++) {
- s=r++;
- s->next=r;
- }
- }
- // Gets a node from the pool. Returns NULL if pool is empty. (A BETTER DESIGN)
- struct record * new_node()
- {
- struct record *r=pool;
- pool=(pool *)malloc(sizeof(pool[POOL_SIZE]));
- }
- // Push a node to the pool.
- void free_node(struct record *r)
- {
- r->next=top;
- top=r;
- }
when i try to compile this, i meet up with those errors.
memory.c: In function ‘new_node’:
memory.c:29:15: error: expected expression before ‘)’ token
pool=(pool *)malloc(sizeof(pool[POOL_SIZE]));
^
how could i fix this error?