In fact it is good practice to use struct wrappers for void* pointers to get type safety. On the other hand, a typedef is just for programmer convenience and the compiler doesn't care.
There is a point, perhaps a little specious, that you put a module's data structures behind a typedef so the interface doesn't change if it changes from a simple data type to a struct. Probably doesn't happen too often.
The perfect C object-oriented-style interface is FILE* from stdio.h. A FILE is a structure full of operating-system-specific file information but you never have to see it or worry about what's in it, you just use the functions.
you could never do this in C. If it is a "value type" i.e. a non-pointer, then you cannot change the size of the value, without changing the ABI and the function decl.
Technically, int32_t is bad in that way, but we are not fooled by it.
Meaning? On my system int32_t is directly typedefed to unsigned int, absolutely no hidden pointers or conversions.
I do care about the size of a struct sometimes, but that would require me to go to the definition of the struct, so just seeing the word "struct" didn't help me one bit.
And I of course care about the members of the struct, but that again requires me to know what the actual members are which the word "struct" doesn't give me.
So what exactly does omitting the word "struct" hide again?
Like, my variable is already declared as `int meters` probably. I don't need the redundancy of saying `meters_t meters`. Maybe I even want to store meters as a `long` in certain contexts.
Hard disagree.
Life safer when dealing with things like SI unit types. I used to use lots of suffixes - _km, _m, _seconds, _hours, but I found that to be a lot more noisy (especially derived units and Nth order stuff like acceleration, seconds_per_second, etc) and evidently it would sneak in errors when you started doing calculations and passing them to functions.
Definitely want different types when I have these three representations flowing around in the program:
pressure_bits_t - raw data from the sensor, gets filtered/averaged in this form, then converted to one of these at various stages:
pressure_pascal_x10_t - integer pascal * 10 (i.e fixed point, one decimal)
pressure_millibar_t - floating point in millibar
Only ISO C can reserve things, no one else, and ISO C does not reserve the _t suffix.
NOOoooooo, please stop doing this. unless you are a library author who gets to define things like uint8_t, please do not do this
> Use struct wrappers for strong typing
even BIGGER no. This is completely misunderstanding what a typedef is and what it should be used for.