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
It can't reference itself in that example.
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)
{
/*...*/
}