# Thread: typeundef???

1. ## typeundef???

I know this is a silly question: Is there a way to undefining user defined type?

Example:

Code:
```typedef struct Node
{
int data;
struct Node *next;

} Node;

...your singly-linked list code here...

typeundef Node;

typedef struct Node
{
int data;
struct Node *previous;
struct Node *next;
} Node;

...your doubly-linked list code here...```
Any trick exists? (~^_^~)

2. Why would you wanna do that?

BTW,
Doubly linked-list? What do you mean?

3. I know that you can do #undef macroname, but I am not sure if it would work with structs.

4. That question struck me quite a while ago, too. The answer I found is "no".

5. BTW,
Doubly linked-list? What do you mean?
An interesting linear data structure:
http://en.wikipedia.org/wiki/Linked_list

6. Originally Posted by audinue
An interesting linear data structure:
http://en.wikipedia.org/wiki/Linked_list
I know what is a linked-list, I implement these generic data structures (stacks, binary trees, queues) in C#, but I always use a single linked-list, not a doubly, it's not necessary since you can do the same thing with a single one.

cyberfish --> Yep, kinda figured. actually my questions referred to its necessity more than what it is (could understand from the code)

7. one in which each node contains BOTH a pointer to the next node AND a pointer to the previous node. That way you can traverse the list both ways.

8. There's no way to undo a typedef. Only macros.

9. So, what is the best way to define data structures to avoid collision with another?

10. Collisions aren't likely unless you come up with bland names. You could always come up with a decent naming convention if you're implementing a library.

11. But is it possible to redefine a user defined type?
Code:
```typedef struct Node
{
int data;
struct Node *next;

} Node;

// Use Node here

typedef struct Node
{
int data;
struct Node *previous;
struct Node *next;
} Node;

// Use new definition here```
If this isn't possible (I don't have a compiler handy at the moment) then no big deal. Just use a different name. If the feature was really required in C, it would be implemented.

12. I imagine that would kind of ruin typing for functions that accept typedef'ed arguments.

13. You'd run into two problems there, both the redef of "struct Node" and its re-typedef. Either way you slice it, unique names should be used.
The best you could hope for is to hack it with the pre-processor:
Code:
```#define Node struct _Node1
struct _Node1
{
int data;
struct _Node1 *next;

} ;

// Use Node here

#undef Node
#define Node struct _Node2
struct _Node2
{
int data;
struct _Node2 *previous;
struct _Node2 *next;
} ;

// Use Node here```
if you were say merging code and absolutely needed to preserve the "Node" identifier.

14. Wasted effort.
Just use different names.
Besides, if you are implementing a double-linked list, what use is a single-linked list?

15. A single-linked list offers less functionality but is more memory-efficient in what it does?

Popular pages Recent additions