Author Topic: Linked list in CW7.1  (Read 7749 times)

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Linked list in CW7.1
« on: June 12, 2009, 09:18:41 PM »
I'm trying to make a buffer that grows as the size of the data does, and so I'm trying  a linked list.  The code I have compiles and works fine in MSVC and the simulator, but CW won't compile it. 
It says:
Code: [Select]
Error   : illegal implicit conversion from 'unsigned long **' to 'unsigned long *' my_uart.c line 245     fnAddNode(&pList, RXBuffer); 
Error   : illegal implicit conversion from 'unsigned long *' to 'unsigned long **' my_util.c line 107      pTmpNode = *pTmpNode; 
I've following the examples from http://en.wikipedia.org/wiki/Linked_list#Language_support

Here is my code:
Code: [Select]
unsigned long *pList=NULL;
void fnProcessRx(CHAR *RXBuffer, QUEUE_TRANSFER length){
    fnAddNode(&pList, RXBuffer);  //this line fails in the compiler (line 245)
}

Code: [Select]
//take an array and allocate a chunk of ram for it on the heap
//then copy the array into the data section
//structure is an array: |ptr|string data|
void fnAddNode(unsigned long** pNode, CHAR * data){
unsigned long * pTmp;
unsigned long **pTmpNode;

pTmpNode = pNode;

pTmp = uMalloc(uStrlen(data)+1+4); //extra bytes added, one for the NULL string terminator and 4 for the address pointer
if (pTmp == NULL) {
//return NULL;
}
*pTmp=NULL; //make sure that the new pointer is NULL

uStrcpy((CHAR*)(pTmp+1),data); //copy the data into the new link node

//go to the end of the list to add
if (pTmpNode != NULL) {
while (*pTmpNode != NULL) {
pTmpNode = *pTmpNode;  //this line fails to compile in CW
}
*pTmpNode = pTmp;
}else{
//the list appears to be empty
//*pNode = pTmp;
*pNode = pTmp;
}
}

If anyone has any pointers (no pun intended) that would be great!

Thanks,
Aaron
« Last Edit: June 12, 2009, 09:20:15 PM by alager »

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: Linked list in CW7.1
« Reply #1 on: June 12, 2009, 09:38:22 PM »
I think I got it figured out, I needed some explicit casts.
Code: [Select]
fnAddNode((unsigned long *)&pList, RXBuffer);and
Code: [Select]
pTmpNode = (unsigned long **)*pTmpNode;
This still works in the simulator and now CW compiles it just fine.

Aaron