Thread: struct/pointer warning

  1. #1
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154

    struct/pointer warning

    Something quick.
    This is my struct
    Code:
    typedef struct _Node
    {
     int ID;
     char *Name;
     int ParentID;
     int Date_of_birth;
     char *Place_of_birth;
     int SpounceID;
     int k;
     int *ChildrenID;
     
     int Generation;
     struct Node *next_family;
     struct Node *parent;
     struct Node *spounce;
     struct Node *children;
    }Node;
    Check out Node pointers. I get warnings where i use for example this temp= temp->next_family; in my code in order to move to the next node.
    I've replaced it with temp=(Node *)temp->next_family; and warnings stoped but is it ok to do that or there is another way (more safe) to avoid those warnings ?

    Thanks in advance

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You don't have struct Node defined anywhere. You do have a struct _Node.

  3. #3
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154
    Thanks tabstop
    I use this and i've got no warnings
    Code:
    typedef struct _Node Node;
    
    struct _Node
    {
     int ID;
     char *Name;
     int ParentID;
     int Date_of_birth;
     char *Place_of_birth;
     int SpounceID;
     int k;
     int *ChildrenID;
     
     int Generation;
     Node *next_family;
     Node *parent;
     Node *spounce;
     Node *children;
    };
    But what is the difference from the above ?
    So far i thought nothing changes and that was a different way to write.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can't use a typedef name until after you've defined it. In your original, the name "Node" (NOTE NOT "struct Node") was not available to use until you got to the semicolon after the word Node. And of course Node is not the same as struct Node (you can never get "struct Node" out of a typedef).

  5. #5
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154
    Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM