I know that if the data type declaration is omitted in C/C++ code in such way: unsigned test=5;, the compiler automatically makes this variable an int (an unsigned int in this case). I’ve heard that it’s a C standard and it will work in all compilers.
But I’ve also heard that doing this is considered a bad practice.
What do you think? Should I really type unsigned int instead of just unsigned?
Are short, long and long long also datatypes?
unsignedis a data type! And it happens to alias tounsigned int.When you’re writing
unsigned x;you are not omitting any data type.This is completely different from “default
int” which exists in C (but not in C++!) where you really omit the type on a declaration and C automatically infers that type to beint.As for style, I personally prefer to be explicit and thus to write
unsigned int. On the other hand, I’m currently involved in a library where it’s convention to just writeunsigned, so I do that instead.