I’m studying an application in C for ARM low-powered devices, I have this piece of code in the first place
struct state {
float position;
int dummy;
};
notice how this struct does not define a new type, I also have noticed that later in the code this struct is used like this
struct state mystate;
which is something odd and not convenient to me, not flexible and with 1 extra useless keyword that i can easily avoid just using typedef for the struct in the first place.
This is a struct that is vital for the business logic of this application and is also used a lot in the source code.
There is a particular reason for not using typedef with a struct that in the end is used as a type?
I consider typedef harmful. I think it almost invariably mis-used. In my opinion, it is useful and only useful when the underlying type is FULLY abstracted – e.g. ALL manipulation is through functions. Otherwise, the underlying type is not abstracted – the user still has to know what it is, to make sense of the code – all that has happened is that code readabiliy has been impaired, where the type namespace has been without gain (for the type is not properly abstracted) extended.
In my view, almost all use of typedef lacks understanding of the problems it brings and how it ought to be used.