I was wondering why you would use the specifier typedef on the types struct and union, because aren't they somewhat used to define your own type anyways?
Thanks!
I was wondering why you would use the specifier typedef on the types struct and union, because aren't they somewhat used to define your own type anyways?
Thanks!
Edit Reading the standard the 'typedef' isn't required in C++ and is probably there for backward compatibility. Also, with 'typedef' the code would compile in both C and C++ compilers without change or '#if define' around it so it's probably a legacy code support thing.
I think people do it to save on typing! We're a lazy lot afterall. So instead of:-
struct SomeStruct
{
// some data
};
struct SomeStruct first_instance;
struct SomeStruct second_instance;
you'd have this instead:-
typedef struct typedefSomeStruct
{
// some data
} SomeStruct;
SomeStruct first_instance;
SomeStruct second_instance;
So when you declare instances of the type you don't need to prefix the 'struct' keyword.