By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

What is the damn difference?!?!?

P: 44
Hey you all, ive been confrontated with a bizarre thing: im doing a binary tree in C and in the file Tree.h i did this:

//headers & other stuff
typedef struct Node Node_t;

struct Node{

char data;

Node_t * left;
Node_t * right;
};

//functions protos...


Then in Main.c, after all the includes and etc, i get a compilation error for trying to declare a Node_t variable, just like this:

//Main.c
//headers, ....

int Main(void){

Node_t * root; //compilation error

//....
}


But if i do this in the Tree.h instead of above:

typedef struct{

char data;

Node_t * left;
Node_t * right;
}Node_t;


...this time in the Main.c i dont get any compilation error.

Can anybody explain this???
Aug 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: 1
[b]//headers & other stuff
typedef struct Node Node_t;
A user-defined struct Node with no fields that can be referred to as Node_t?
compilation failure.

typedef struct Node{ missing fields here; } Node_t;

typedef struct{

char data;

Node_t * left;
Node_t * right;
}Node_t;

defining a struct with parameters inside brackets which can be referred to as Node_t.

Priceless. For everything else, there's mastercard.
Aug 7 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.