3 ms·
>even BIGGER no. This is completely misunderstanding what a typedef is and what it should be used for. Hard disagree. Life safer when dealing with things like
by properparity 4y ago
>even BIGGER no. This is completely misunderstanding what a typedef is and what it should be used for.
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
- heywhatupboys 4y ago_t is even a "reserved" suffix in C. Stop using it. If you want compile-time type safety, pick another language like Haskell. A "typedef" is by no means a contract declaration in C.
- mh7 4y agoNo it is not reserved, it's just posix's personal style guides. There's just as much of a name clash possibility when not using _t because lots of other libraries and platforms uses some other convention. Only ISO C can reserve things, no one else, and ISO C does not reserve the _t suffix.
- heywhatupboys 4y agoI think it is pedantic to say that POSIX's guidance is not the de-facto C standard, or at least that the union of rules between ISO and POSIX