IonicWind Software

Aurora Compiler => General Discussion => Topic started by: LarryMc on March 03, 2006, 09:46:32 AM

Title: Strange looking structure
Post by: LarryMc on March 03, 2006, 09:46:32 AM
This is in the acommon.inc:
Quotestruct _linked_list
{
   _linked_list *pNext;
   _linked_list *pPrev;
   pointer pData;
}
I don't understand that.

Larry
Title: Re: Strange looking structure
Post by: Zen on March 03, 2006, 09:55:36 AM
Its basicly a structure used for the location of the data used in linked lists. It stores the next and previous locations in memory of the data. And pData stores the actual data.

Lewis
Title: Re: Strange looking structure
Post by: LarryMc on March 03, 2006, 10:34:20 AM
What it looks like to me though is:
it's a struct whose 1st two elements are of a type struct(the same one) who's 1st two elements are of a type struct(the same one) who's 1st two ........ad infinitem(sp)

like
struct s1
{
  s2 item1;
  int item2;
}

struct s2
{
  s3 item3;
  int item4;


struct s3
........

but with struct _linked_list  s1,s2,s3 are all the same structure

it looks like you're using a structure inside of it self which would make it nested to infinity.

Larry
Title: Re: Strange looking structure
Post by: Parker on March 03, 2006, 10:49:00 AM
But those two elements are pointers. You're right, if it said _linked_list prev; it would be nested to infinity, and the compiler would probably report an error - either that or go into an infinite loop.

A typed pointer can be confusing at first, it was when I first learned C. But a pointer to anything is just an address, and the type just tells the compiler that you don't have to explicitly cast when you dereference it.

That's the power of a linked list, the nesting for however many levels you need. For example, if you had a large list, this is completely fine to write:
void *pData = pList->pNext->pNext->pNext->pNext->pNext->pNext->pNext->pData;
Title: Re: Strange looking structure
Post by: Ionic Wind Support Team on March 03, 2006, 10:52:16 AM
The '*' denotes a pointer to a type.

int *p;

is a pointer to an integer.