Thread: nested structures and pointers

  1. #1
    Codus Conjectus spongefreddie's Avatar
    Join Date
    Sep 2010
    Location
    USA
    Posts
    86

    nested structures and pointers

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

    Code:
    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:

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

    Code:
    List * plist;
    
    plist->head->item;
    // and/or
    plist->end->item;
    I ask because I had a structure assignment that used to work:

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

    Code:
    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?
    V8 Interceptor: KDE 5.25.5 on Manjaro Linux 22.0.0 "Sikaris"
    Steering wheel: gcc 12.2.0 in Kate
    Supercharger: NASM 2.15.05
    Engine: AMD Ryzen 7 1700
    Dashboard: NVIDIA GeForce GTX 1060 6GB
    Rusty old trailer for hauling 3% of my Steam catalog: Windows 7 Pro 64bit SP1
    3 Antique Ford Model T automobiles for vintage LAN gaming: Windows XP SP3
    Sturdy buckboard for DOS LAN gaming: DOSBox 0.74-3 on Windows XP SP3

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    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