Connecting Tech Pros Worldwide Forums | Help | Site Map

Explain this !

Ravi Uday
Guest
 
Posts: n/a
#1: Nov 14 '05
Hi,

Can anybody explain this..

#define LIST_DESTROY(a) list_destroy(a)
#define LIST_ENQUEUE(a, b, c) list_enqueue(a,b,c)
#define LIST_REMOVE(a, b, c) list_remove(a,b,c)
etc...


#define LIST_DESTROY(a) NULL
#define LIST_ENQUEUE(a, b, c) NULL
#define LIST_REMOVE(a, b, c) NULL
#define LIST_HEAD_ELEMENT(a) NULL
#define LIST_GET_DATA(a) NULL
#define LIST_NEXT_ELEMENT(a) NULL
#define LIST_EMPTY(a) NULL

#define FOR_ALL_DATA_IN_LIST(__list, __element, __data) \
for (__element = LIST_HEAD_ELEMENT(__list), \
__data = LIST_GET_DATA(__element); \
__element != NULL; \
__element = LIST_NEXT_ELEMENT(__element), \
__data = LIST_GET_DATA(__element))


Though the name of the MACRO is self-explanatory what i dont understand is
the second list of #define's - why are they defined as NULL

Thanks,
- Ravi

Ronald Landheer-Cieslak
Guest
 
Posts: n/a
#2: Nov 14 '05

re: Explain this !


Ravi Uday wrote:
[color=blue]
> Can anybody explain this..[/color]
Possibly..
[color=blue]
> #define LIST_DESTROY(a) list_destroy(a)
> #define LIST_ENQUEUE(a, b, c) list_enqueue(a,b,c)
> #define LIST_REMOVE(a, b, c) list_remove(a,b,c)
> etc...
>
>
> #define LIST_DESTROY(a) NULL
> #define LIST_ENQUEUE(a, b, c) NULL
> #define LIST_REMOVE(a, b, c) NULL
> #define LIST_HEAD_ELEMENT(a) NULL
> #define LIST_GET_DATA(a) NULL
> #define LIST_NEXT_ELEMENT(a) NULL
> #define LIST_EMPTY(a) NULL
>
> #define FOR_ALL_DATA_IN_LIST(__list, __element, __data) \
> for (__element = LIST_HEAD_ELEMENT(__list), \
> __data = LIST_GET_DATA(__element); \
> __element != NULL; \
> __element = LIST_NEXT_ELEMENT(__element), \
> __data = LIST_GET_DATA(__element))
>
>
> Though the name of the MACRO is self-explanatory what i dont understand is
> the second list of #define's - why are they defined as NULL[/color]
In divination mode, I'd say there's probably an #if or an #ifdef
somewhere, but I think this link may be helpful:
http://www.catb.org/~esr/faqs/smart-questions.html

HTH

rlc
vir
Guest
 
Posts: n/a
#3: Nov 14 '05

re: Explain this !


Ravi Uday wrote:[color=blue]
> Hi,
>
> Can anybody explain this..
>
> #define LIST_DESTROY(a) list_destroy(a)
> #define LIST_ENQUEUE(a, b, c) list_enqueue(a,b,c)
> #define LIST_REMOVE(a, b, c) list_remove(a,b,c)
> etc...
>
>
> #define LIST_DESTROY(a) NULL
> #define LIST_ENQUEUE(a, b, c) NULL
> #define LIST_REMOVE(a, b, c) NULL
> #define LIST_HEAD_ELEMENT(a) NULL
> #define LIST_GET_DATA(a) NULL
> #define LIST_NEXT_ELEMENT(a) NULL
> #define LIST_EMPTY(a) NULL
>
> #define FOR_ALL_DATA_IN_LIST(__list, __element, __data) \
> for (__element = LIST_HEAD_ELEMENT(__list), \
> __data = LIST_GET_DATA(__element); \
> __element != NULL; \
> __element = LIST_NEXT_ELEMENT(__element), \
> __data = LIST_GET_DATA(__element))
>
>
> Though the name of the MACRO is self-explanatory what i dont understand is
> the second list of #define's - why are they defined as NULL
>
> Thanks,
> - Ravi[/color]
It's seems that the user of this library must provide his redefinitions
of macroses that have been defined as NULL to use this. The main purpose
is something like C++ template construction. I don't know the details
and I can't comment the design. Sometimes it's better to use void*
instead of macroses in C. But if you really need lots of generic
procedures try switching to C++.

--
vir
Closed Thread