I have a question in nested structures ( C programming):  
Author Message
mveeravagu





PostPosted: Visual C++ Language, I have a question in nested structures ( C programming): Top

I have a question in nested structures ( C programming):

struct s1{

int x;

int y;

};

struct s2 {

struct s1 var[10];

int p;

int q;

};

struct s2 nested[100];

Is "struct s1 var[10]" is a correct construct

Thank you.



Visual C++8  
 
 
David Gorena Elizondo - MSFT





PostPosted: Visual C++ Language, I have a question in nested structures ( C programming): Top

Moving to a more appropriate forum

Thanks,
David Gorena Elizondo
[MSFT] VSTS


 
 
kuphryn





PostPosted: Visual C++ Language, I have a question in nested structures ( C programming): Top

Correct.

typedef struct x0
{} x1;

Kuphryn


 
 
mveeravagu





PostPosted: Visual C++ Language, I have a question in nested structures ( C programming): Top

The typedef is not clear to me. I am trying to have an array of structure within an array of structure as I explained in the initial post. I am try to do this in C - program and not in C++

Thank you.


 
 
Jonathan Caves - MSFT





PostPosted: Visual C++ Language, I have a question in nested structures ( C programming): Top

Your code is correct C but this is one of the areas of real confusion in C and and one that can lead to really subtle bugs. As has already been stated above I would use a typedef to get the name of the user-defined type in to the global namespace - this makes it explicitly clear what is going on and removes all sources of confusion - especially for any developers who are coming to C from C++ - which is more and more common.