Results 1 to 3 of 3
Hi All,
I have create a linked list using union, is this possible???
If yes can you please show the snippet???...
- 08-26-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 49
Linked list - union
Hi All,
I have create a linked list using union, is this possible???
If yes can you please show the snippet???
- 08-26-2008 #2
I don't know lets see your code
- 08-26-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Mmmm, your post is a bit strange.
If you have created it, then it is possible (the creation of an entity, even a list, automatically implies that the said entity exist). However, unless you are pursuing a very concrete purpose, the union itself has nothing to do with a list.
It's possible to implement complex types like lists of union nodes, or even unions of linked lists (though that's highly counterproductive in terms of memory usage).
So I am inclined to think that your post is full of typos and you are just asking if it's possible. The straight answer is no. If you have some code, show us so we can discuss a bit about it.
I like to think of unions as the OR version of struct (it's just my mental model, never ever say that to a teacher if that's what you are after). A union stores one of it's member only. If an union holds int a; float b; char c; it will only store one of the three (a OR b OR c), but initially it will reserve memory for the biggest of them (float in this case). Struct in the contrary can store a AND b AND c because it reserves memory for the three of them separately.
Alternatively, describe *what* you are after, so we can tell you the alternatives on *how* to achieve it.
I hope I didn't confuse you too much, and sorry if what I am explaining is too trivial. Cheers


Reply With Quote
