typeof() and extern

Programming, for all ages and all languages.
Post Reply
afritmans
Posts: 4
Joined: Mon Feb 06, 2012 10:15 am

typeof() and extern

Post by afritmans »

Hi everyone!

I'm strugling with the following problem in TCC. I wrote some general linked list functions, like the one below:

Code: Select all

#define klibLinkedListPopFront(list)             \
    ({                                           \
        typeof(list) tmpItem = list;             \
		if(list != NULL)                         \
		{                                        \
		    list = tmpItem->next;                \
		    tmpItem->next = NULL;                \
	    }                                        \
		tmpItem;                                 \
	})
Most of the time, this works quite good. But when I try to use this function on a list which is declared as 'extern 'in a header file:

Code: Select all

// In header file:
extern PCB* readyQueue;
// In C file:
klibLinkedListPopFront(readyQueue);
The linker compains about 'undefined reference tmpItem', because

Code: Select all

typeof(list) tmpItem
becomes

Code: Select all

extern PCB* tmpItem
Is this normal behavior, or a TCC bug? Anyone knows an easy way to make my list generic?

Thanks in advance!
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: typeof() and extern

Post by JamesM »

Anyone knows an easy way to make my list generic?
Use casts to void*, which is the "C way", or use C++.
Post Reply