CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Recursively defined structures

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sraiderk



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

Recursively defined structures
PostPosted: Thu Jan 24, 2008 9:26 am     Reply with quote

Recursively defined structures not permitted why?

typedef struct x
{
struct x y *z1
struct x y *z2
} sdf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 24, 2008 11:49 am     Reply with quote

It probably doesn't work, but if you want us to test it, you need to
post code that is compilable on at least some compiler (like MSVC).
Your current code is not compilable.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Jan 25, 2008 2:10 am     Reply with quote

First of all your code is flawed.
You are missing commas and a semicolons.
You are also redefining y.


Now the problem is it will take up infinate space as when you create the structure (The sdf at the end does this) it then goes on to reserve memory for itself and within that you create another version of itself, the struct x y, *Z1; does this. The pointer is OK but the struct x y actually reserves memory for a new structure and calls it y (sdf.y). This in turn creates another structure of type x with a struct y in it (sdf.y.y) and so on and so on (sdf.y.y.y.y.y.y.y.y.y......).

As I said, pointers are ok so:-

typedef struct X {
struct X *z;
} myX;

Is the way you should do it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group