If you want to use Qt, you have to embrace quint8
, quint16
and so forth.
If you want to use GLib, you have to welcome guint8
, guint16
and so forth.
On Linux there are u32
, s16
and so forth.
uC/OS defines SINT32
, UINT16
and so forth.
And if you have to use some combination of those things, you better be prepared for trouble. Because on your machine u32
will be typedef
d over long
and quint32
will be typedef
d over int
and the compiler will complain.
Why does everybody do this, if there is <stdint.h>
? Is this some kind of tradition for libraries?
typedef is a reserved keyword in the programming languages C and C++. It is used to create an additional name (alias) for another data type, but does not create a new type, except in the obscure case of a qualified typedef of an array type where the typedef qualifiers are transferred to the array element type.
typedef is limited to giving symbolic names to types only, whereas #define can be used to define an alias for values as well, e.g., you can define 1 as ONE, 3.14 as PI, etc. typedef interpretation is performed by the compiler where #define statements are performed by preprocessor.
typedef'ing structs is one of the greatest abuses of C, and has no place in well-written code. typedef is useful for de-obfuscating convoluted function pointer types and really serves no other useful purpose.
No difference in execution time, so you should be fine using either for competitive programming. I personally avoid #define and use typedef for types as it is more cleaner and readable.
stdint.h
didn't exist back when these libraries were being developed. So each library made its own typedef
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With