Thread: Inter-dependent structs for doubly-linked list

  1. #1
    Registered User creek23's Avatar
    Join Date
    Jun 2010
    Location
    Philippines
    Posts
    17

    Inter-dependent structs for doubly-linked list

    I'm trying to implement a different kind of doubly-linked list. It's made up of 2 different structs that are inter-dependent.

    PHP Code:
    [code]
    typedef struct {
        
    int value;
        
    Child *child;
    Parent;

    typedef struct {
        
    int value;
        
    Parent parent;
    Child;
    [/
    code
    What should I do for the compiler to know that Child data-type is defined below as struct?

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    You can forward declare the Child struct before you define the Parent struct. Note that this only works with pointers.
    Code:
    struct Child;

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    45
    or typedef then declare

    Code:
    typedef struct child Child;
    // OR
    typedef struct child *Child;
    
    struct child {
    ...
    };

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

Tags for this Thread