Thread: nested structures and pointers

  1. #1
    Codus Conjectus spongefreddie's Avatar
    Join Date
    Sep 2010

    nested structures and pointers

    I have a conceptual question. If I have some structures declared thus:

    struct film
       char title[TSIZE];
       int rating;
    typedef struct film Item;
    typedef struct node
       Item item;
       struct node * next;
    }  Node;
    typedef Node * List;
    And I decide to re-define List as:

    // typedef Node * List;
    typedef struct list {
       Node * head;
       Node * end;
    } List;
    Would the references to the item member of Node then become:

    List * plist;
    // and/or
    I ask because I had a structure assignment that used to work:

    static void CopyToNode(Item item, Node * pnode)
       pnode->item = item;  // copying structure
    After the 'List' definition change (mentioned above), I changed the CopyToNode() to:

    static void CopyToNode(Item item, List * plist)
       plist->end->item = item;  // copying structure
    The files compile with no errors, but the program crashes on the 'copying structure' line.

    What am I forgetting?
    Steering Wheel: gcc in Code::Blocks 16.01
    Batmobile: Manjaro 17.0 64bit Cinnamon, kernel 4.9.44-1-MANJARO
    Engine: AMD FX-8350 Vishera 8-core
    Dashboard: NVIDIA GeForce GTX 1060 6GB
    Rusty old trailer for hauling games: Windows 7 Pro 64bit SP1
    Roach-infested ORV for composing music: Windows 7 Pro 64bit SP1

  2. #2
    Registered User
    Join Date
    May 2010
    Is plist pointing to valid memory location?
    If so, how about plist->end?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector of arrays of pointers to structures
    By Marksman in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 04:44 AM
  2. Help with nested struct pointers
    By vampireiam in forum C Programming
    Replies: 10
    Last Post: 11-13-2007, 11:59 AM
  3. Structures, and pointers to structures
    By iloveitaly in forum C Programming
    Replies: 4
    Last Post: 03-30-2005, 06:31 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Freeing pointers in structures
    By jim50498 in forum C Programming
    Replies: 4
    Last Post: 03-08-2002, 12:53 PM