October 30, 2025, 08:59:07 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Strange looking structure

Started by LarryMc, March 03, 2006, 09:46:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

This is in the acommon.inc:
Quotestruct _linked_list
{
   _linked_list *pNext;
   _linked_list *pPrev;
   pointer pData;
}
I don't understand that.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Zen

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

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Parker

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;

Ionic Wind Support Team

The '*' denotes a pointer to a type.

int *p;

is a pointer to an integer.

Ionic Wind Support Team