RE: Linked lists in C and C++.

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 10 Oct 2007 22:54:49 -0400

Not sure I understand your question at all?

What exactly are you asking? 

All I was saying is that a struct can't refer to itself, unless if it is in
a pointer type manner, because otherwise it would have to allocate the
entire memory of the struct, and how can you take the size of something that
contains an element whose size depends on an element whose size depends on
an element whose size depeneds on an element ... and so on.


Take care,
Sina

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of jaffar
Sent: Wednesday, October 10, 2007 9:54 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Linked lists in C and C++.

Hi Sina.  Just wondering if in a program that does repeatative actions such
as switching back and forth to a function, repeatative callbacks and so on,
if recursively defined structs  were not advantageous in any way?  Cheers!
----- Original Message -----
From: "Sina Bahram" <sbahram@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, October 11, 2007 8:43 AM
Subject: RE: Linked lists in C and C++.


> Laura handled this, but I wanted to point out that the compiler does 
> know how long to make any pointer on your system, and that's the bit 
> width of your processor architecture, such as 32 bit or 64 bit, so 
> it's ok. Now, if you tried to have a local variable of that struct's 
> type, instead of a pointer, you'd be in trouble, since that would be 
> undefined, or rather recursively defined.
>
> Take care,
> Sina
>
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Graham 
> Hardy
> Sent: Wednesday, October 10, 2007 7:38 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Linked lists in C and C++.
>
> Hi all,
>
> I am creating a linked list in a C++ program, which I can envision as 
> follows.
>
> typedef struct
> {
> /* ... */
> token_t *next;
> }
>  token_t;
>
> (Yes, this list only needs to be linked in one direction.) Clearly the 
> problem is that when I declare the pointer to the next object, though 
> it is a pointer of the type of the members in my list, since that type 
> has not been declared yet, I don't think I can do that. My first 
> instinct told me to use void pointers. Alternatively, I suppose I 
> could declare the struct giving the typename after the keyword 
> 'struct' and before the '{', as, struct token_t { /* ... */ }; Does 
> this method change anything in the way that types are concerned? That 
> is, what is the diference between struct A {/*...*/}; and typedef 
> struct {/*...*/} B;?
>
> And one more question. Despite the 'size' of a given data type being 
> explicit (as, say, a char being 1 byte), I am led to believe that 
> where the actual heap is concerned the alignment is not quite the 
> same, such as 4 or
> 8
> bytes for a char. I believe one can use the directives such as--
>
> #pragma pack (...)
>
> or something akin to that. If so, how does the syntax of this pack 
> function work? It seems that it begins with a keyword of some sort, as 
> to whether the previous alignment should be retained for the future, 
> and then a new value.
> Could someone enlighten me?
>
> Thanks in advance,
>
> Graham.
>
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind
> 

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: