Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Typedef considered harmful?

Name: Anonymous 2011-08-21 14:58

http://www.45mercystreet.com/computing/typedefs.html
I've read this guy's arguments and I'm still not convinced. Typedefs are incredibly useful. Say I'm implementing a tree to store ints but later I want to reuse it to store char*s if I don't use typedef I'm going to need to change every single instance that the int is used. If I had used a typedef I could have defined each node of the tree to contain a key_t and just change the type of key_t in one line. How is this code obfuscation?

So are typedefs harmful or not in your EXPERT opinion?

Name: Anonymous 2011-08-21 17:31

Introducing pointless typedefs like PDWORD and mystruct_t absolutely is code obfuscation.

Using typedefs where you would use templates in C++ is stupid because a typedef can only mean one thing. What if I want a tree of char * and a tree of int? Using #define is better, because you can prefix the function names and use both trees at the same time. But the best is to use the include/linux/list.h technique and don't use a tree containing foos, but foos that contain trees.

Documentation/CodingStyle chapter 5 has some more advice.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List