Are there any potential disadvantages ?
Are there any potential disadvantages ?
I didn't even know we established that many programmers are actually reluctant to using typedef for struct declarations.
One consequence of typedef is that the fact the type is a struct gets lost. If you havethen it's clear that func's argument is a struct.Code:struct blah { ... }; int func(struct blah *ptr) { ... }
If, on the other hand we do:
It's not so clear from just reading the prototype that it's a structure.Code:typedef struct tagblah { ... } blah; int func(blah *ptr) { ... }
Another consequence of typedef is that it (used as above) introduces TWO names to the global namespace, rather than one.
However, I agree with MacGyver, I don't believe that typedef's are underused by "many programmers".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
But you can typedef it to have the same name.
Blah can reference itself and you can also choose whether you add struct when referring to blah or not.Code:typedef struct blah { /*...*/ } blah;
Code:void foo(struct blah* pb) { /*...*/ }
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.