#define error in .h file please help

Started by
4 comments, last by CreepingDeath666 19 years, 2 months ago
I programmed two files, one for linked lists and the other for stacks. I used my link.h file within my stack.h file because I use my linked lists for my stacks. here's my code for each: slist.h #ifndef LIST_H #define LIST_H #include <stdlib.h> typedef struct ListElmt_ { void *data; struct ListElmt_ *next; } ListElmt; typedef struct List_ { int size; int (*match)(const void *key1, const void *key2); void (*destroy)(void *data); ListElmt *head; ListElmt *tail; } List; void list_init(List *list, void (*destroy)(void *data)); void list_destroy(List *list); int list_ins_next(List *list, ListElmt *element, const void *data); int list_rem_next(List *list, ListElmt *element, void **data); #define list_size(list) ((list)->size) #define list_head(list) ((list)->head) #define list_tail(list) ((list)->tail) #define list_is_head(list, element) ((element == (list)->head ? 1 : 0) #define list_is_tail(list, element) ((element)->next == NULL ? 1 : 0) #define list_data(element) ((element)->data) #define list_next(element) ((element)->next) #endif here is the code for stack.h: stack.h #ifndef STACK_H #define STACK_H #include <stdlib.h> #include "slist.h" typedef List Stack; #define stack_init list_init #define stack destroy list_destroy int stack_push(Stack *stack, const void *data); int stack_pop(Stack *stack, const void **data); #define stack_peek(stack) ((stack->head == NULL ? NULL : (stack)->head->data) #define stack_size list_size #endif Whenever I don't comment out: #define stack_init list_init #define stack destroy list_destroy I get these errors: c:\Documents and Settings\Owner\Desktop\Programming\stack\stack.h(12) : error C2146: syntax error : missing ',' before identifier 'list_destroy' c:\Documents and Settings\Owner\Desktop\Programming\stack\stack.h(13) : error C2146: syntax error : missing ',' before identifier 'list_destroy' stack.cpp(9) : error C2146: syntax error : missing ',' before identifier 'list_destroy' stack.cpp(11) : error C2146: syntax error : missing ')' before identifier 'list_destroy' stack.cpp(11) : error C2660: 'list_ins_next' : function does not take 1 arguments stack.cpp(11) : error C2059: syntax error : ')' stack.cpp(21) : error C2146: syntax error : missing ',' before identifier 'list_destroy' stack.cpp(23) : error C2146: syntax error : missing ')' before identifier 'list_destroy' stack.cpp(23) : error C2660: 'list_rem_next' : function does not take 1 arguments stack.cpp(23) : error C2059: syntax error : ')' whenever I comment out those two lines, the program compiles with no problems. In my project, I also include list.cpp which is the implementation of slist.c. I can't figure out why I am getting these errors since I am only #define the two stack functions to equal the list functions. please help
Advertisement
"I also include list.cpp which is the implementation of slist.c"

this should actually say:

I also include list.cpp which is the implementation of slist.h

sorry about that
#define stack destroy list_destroy


should be

#define stack_destroy list_destroy


Note the missing underscore.
#define stack destroy list_destroy

I believe your missing an underscore, did you mean:

#define stack_destroy list_destroy
lol, beat to the punch again :)
lmao wow.....what a noob thing to do. thanks guys. I would have never noticed that. that was the problem.

This topic is closed to new replies.

Advertisement