![]() |
|
#1
|
|||
|
|||
Crazy Linked List ProblemHello :-o
I am new to this forum and this is my first post so excuse me for any errors in my posting. I have been learning c for a few months now and in the 3rd or so rewrite of my first program. I am starting to get into doing more with structs and linked lists and using pointers to hopefully limit the amount of memory used since not all of them need everything. I am at a point where I need to add a struct that hasn't been defined at the point where I need it because it has to be below since it uses the other structs. I have tried to use a void pointer to the struct as a member but it doesn't work and I even tried to type cast it but that didn't help anything other than adding more errors. I'm not sure if I was doing it right since my book I'm learning from never did a cast to a struct so I thought it may have just been outside the scope of the book. My question is: Is it possible to have a void pointer to a struct or union so I don't have to nest them all in the base linked list so I'm not wasting memory and if not is there a way to do what I'm trying to do? ps. Keep in mind that I don't know much yet and my terminology is kinda weak so try not to confuse me past the point I am at now. A BIG THANX in advance for any help you can provide. |
|
#2
|
||||
|
||||
|
Hello MAX_POWER. Welcome to GIDForums™. Did you get your name off a hair dryer
I don't follow your question exactly. Do you have any code snippet that you could post that would explain what you mean? If you post code, keep in mind to use the c-code posting tags ![]() __________________
The best damn Sports Blog period. |
|
#3
|
|||
|
|||
|
hehehe
nope got the name from a simpsons episode ;-) my code is kinda messed up so I would have to do some tweaking since I only wrote it for testing it out and not for use in the program I needed it in since that program has a long way before I can compile it... I'll go and tweak my code and post it |
|
#4
|
|||
|
|||
|
Quote:
Instead of boring you with termonilogy, here's an example with a couple of things you might be interested in. The bottom line is that you can refer to a pointer to a struct even before the struct has been defined. You can have a struct with members that are pointers to the type of struct being defined. That's how linked lists are implemented. Have fun with this: CPP / C++ / C Code:
Any questions? (This stuff is kind of fun when it works.) Regards, Dave |
|
#5
|
|||
|
|||
|
thanx for that info dave
I'm going to try making it work using that info before I try to fix my unfixable test code and post it but if I understand it properly as long as it is a pointer to the struct then it doesn't need to be defined at the time the pointer to it is used in another struct but that is if I understand it properly |
|
#6
|
|||
|
|||
|
Quote:
I think you've got it! (Lots of people do this for a lot longer than you've been at it and never seem to get it.) Enjoy! Regards, Dave |
|
#7
|
|||
|
|||
|
I would just like to say THANX again for the help
I rewrote the test code and it worked... at least after I fixed all my other errors ;-) at least now I know where to go if I have any other questions and thanks for the quickness of the help I been sitting on my code(not literally) for weeks trying to think of a way to get past my problem all I can say is thanks(but not enough) and woohoo I can now continue with the real code and a big THANK YOU to dave for setting me straight |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with the function creating updating a linked list | nkhambal | C Programming Language | 3 | 28-Oct-2004 21:45 |
| bus error in linked list | picknicker187 | C Programming Language | 2 | 08-Oct-2004 11:44 |
| Insert problem in Linked list | Kay Chan | C Programming Language | 1 | 03-Sep-2004 18:06 |
| Insert problem in linked list with two function code | Kay Chan | C++ Forum | 1 | 03-Sep-2004 10:52 |
| help on linked lists any1????? | nick4 | C Programming Language | 1 | 17-May-2004 10:32 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The