LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2003, 12:40 AM   #1
mojozoox
LQ Newbie
 
Registered: Jul 2003
Location: India
Distribution: RedHat 8
Posts: 9

Rep: Reputation: 0
Question 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?
 
Old 08-25-2003, 12:47 AM   #2
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
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.
 
Old 08-25-2003, 02:56 AM   #3
dharmender_rai
Member
 
Registered: Aug 2002
Location: Pune,India
Posts: 39

Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I want .forward to not forward attachments nigelj12 Linux - Software 1 09-30-2004 03:13 PM
need some reference Hamid Moradmand Programming 0 05-17-2004 12:46 AM
cant see .forward file in home directory >> mail forward/copy steve_babbage Linux - Newbie 0 03-02-2004 06:25 AM
C++ Reference qcoder Programming 6 01-13-2004 02:22 AM
c/c++ reference balfred Programming 1 05-10-2002 12:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration