LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Forward reference??? (https://www.linuxquestions.org/questions/programming-9/forward-reference-85372/)

mojozoox 08-25-2003 12:40 AM

Forward reference???
 
(A)

typedef struct node{
int x;
struct node* next;
}*NODEPTR;

(B)

typedef struct node{
int x;
NODEPTR next;
}*NODEPTR;


a forward reference to the struct node* is possible(A) while a forward reference to typedef NODEPTR is not allowed why?

Strike 08-25-2003 12:47 AM

Because the first one isn't a forward reference. "struct node" is in the symbol table already, it's just not fully defined yet. In the latter example, there's nothing in the symbol table that matches "NODEPTR" when it gets to the first declaration that uses it.

dharmender_rai 08-25-2003 02:56 AM

typedef struct node{
int x;
struct node* next;
}*NODEPTR;
### Not a forward reference case as struct node is already known to the compiler and an entry has been made into the symbol table
(B)

typedef struct node{
int x;
NODEPTR next;
}*NODEPTR;
## forward reference case.
You can do as B) but with following modifications:

typedef struct node* NODEPR;
// here the compiler will enter the information in the symbol table for both of the entries.
typedef struct node{
int x;
NODEPTR next;
}*NODEPTR;


--- Dharmender Rai


All times are GMT -5. The time now is 02:49 PM.