VERBOSE (ERROR, fprintf (stderr, "can't allocate memory\n"));
return NULL;
}
+ new->ops = (element_t **) calloc (1, sizeof (element_t *));
+ if (new->ops == NULL) {
+ free (new);
+ VERBOSE (ERROR, fprintf (stderr, "can't allocate memory\n"));
+ return NULL;
+ }
new->func = function;
new->nbops = nbops;
new->prio = prio;
void delelement (element_t *root)
{
- int i;
if ((root != NULL) && (root != ERROR_OP)) {
+ int i;
for (i = 0; i < root->nbops; i++) {
if ((root->ops[i] != NULL) && (root->ops[i] != ERROR_OP)) {
delelement (root->ops[i]);
}
}
+ if (root->nbops) {
+ free (root->ops);
+ }
free (root);
}
}
/* calculus element type */
-#define MAX_OPERANDS 10
typedef struct _element_t {
func_t func;
int nbops;
- struct _element_t *ops[MAX_OPERANDS];
+ struct _element_t **ops;
double value;
int prio;
} element_t;