Inter-dependent structs for doubly-linked list

This is a discussion on Inter-dependent structs for doubly-linked list within the C Programming forums, part of the General Programming Boards category; I'm trying to implement a different kind of doubly-linked list. It's made up of 2 different structs that are inter-dependent. ...

  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, 11:01 AM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 06:46 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

Tags for this Thread


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