Name: Anonymous 2011-11-24 12:59
Why must they feel the need to redefine all the primitives with different names?
const) pointer to it in order to achieve the same effect. It is also bad to directly return structures; a pointer to an output buffer is usually better. And while it is ok to stack-allocate int arrays in the stack, you'd rather avoid it with structures, since they can be much larger than an int, and may trash your stack area. With a structure, you expect it to be larger than you typical int variable, and you will refrain from doing a lot of things which you would do with scalar types.typedef struct is bad in a number of aspects. First, they disguise a structure as being an ordinary scalar type: it is hard to tell whether it is really a redefined scalar type (which is also bad), hard to tell whether it is addressable, whether they can be dereferenced (if pointers to structures), and so on. People may even attempt to do arithmetic with it, as if the type were really a scalar type (think about someone implementing a binary tree with your structure type as data, and using plain subtraction as a comparation criteria -- it won't work on aggregate types).
typedef struct my_struct {
// ...
} my_struct;typedef to structure types will do the same with unions. By simply looking at the type you can't differentiate a structure from a union, and the access to them is exactly the same (and they can even contain exactly the same members). While strong syntax is no excuse for lack of proper testing, in this particular case the syntax does help to better understand the code and avoid stupid mistakes.typedef in C is, in common practice, bad not only on structures, but in everything else. A typedef does not declare a new type: it's just an alias the compiler will happily ignore. Thus, it helps to do what should not be done in C: hiding information from the programmer. You can't properly printf() or scanf() typedef'fed variables, since you can't say if it is an int or long. You can't bitwise operate in it because it might be a float. You can't assign to it safely: it might be const. typedef is roughly meant to substitute #define, thus it limits itself to almost only what #define can achieve. It is meant to create opaque types due to standard-wide constraints and other implementation-specific issues, and even then, these types are very well documented.typedef together with unions (without the same sizing problems, but with the same syntactical unawareness problems), enumerations (namespace pollution) and types in general, when it is visibly not needed.