Difficult linked list question.

This is a discussion on Difficult linked list question. within the C Programming forums, part of the General Programming Boards category; I'm not going to post all 1100 lines of BSD code for this question. The question stems from the following ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195

    Difficult linked list question.

    I'm not going to post all 1100 lines of BSD code for this question.


    The question stems from the following declaration in a singly linked list.

    Code:
    struct generic_node { 
          void *data; 
          struct generic_node *next; 
    };
    1)How can this declaration not be typesafe?
    2)How can this not have internal storage?

    Explanation, sample line code, or anything else would be appreciated.

    Thanks

  2. #2
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    sounds like a homework assignment.
    And it's so simple that anyone thinking it difficult can't have paid attention in class.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    I would almost find humor in the response, but it's been well over 15 years since I've been in school. I was asking the question becuase I was wondering about the TAILQ and CIRCLEQ macros found in NetBSD.

    Also, if you looked at an earlier post, I had asked about aliasing. I'm trying to make heads or tails how the various BSD's implement linked lists. This means trying to understand the various sheep tricks used by the engineers.

  4. #4
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    ok, well here goes nothing.

    You're using void pointers.
    That means you're loosing whatever type checking you might have had.
    You're also not storing the data itself in the list since you're using pointers to data instead of the data itself.

    I thought everyone would be able to figure that out.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    Unless they are confronted with 1100 lines of hostile code. Then we hit panic mode and forget everything we learned. I guess it would be like a person that learned hand to hand fighting, but froze up when they were attacked in real life.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    2)How can this not have internal storage?
    It's a pointer to something else. That something else isn't in the structure.

    Is that what you meant? And is 1) answered?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list question
    By brb9412 in forum C Programming
    Replies: 16
    Last Post: 01-04-2009, 03:05 PM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  3. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 05:40 PM
  4. linked list question
    By yeahdixon in forum C++ Programming
    Replies: 2
    Last Post: 03-28-2002, 08:16 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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