struct/pointer warning

This is a discussion on struct/pointer warning within the C Programming forums, part of the General Programming Boards category; Something quick. This is my struct Code: typedef struct _Node { int ID; char *Name; int ParentID; int Date_of_birth; char ...

  1. #1
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142

    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,185
    You don't have struct Node defined anywhere. You do have a struct _Node.

  3. #3
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142
    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,185
    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
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142
    Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 04:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03: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, 07:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21