T
The Unlord
Hi,
I'm currently using a lot of other people's code, and I kept stumbling
upon what looked to me as a 'weird habit':
In some general include dir there's a file with a bunch of typedefs like
typedef unsigned char UINT8; //!< 8 bits of unsigned integer
nothing wrong with that, I guess, but on every occasion where a type
like that is assigned, you see things like this:
UINT8 Dummy = static_cast<UINT8>(0);
I personally completely fail to see the logic in that...
I thought compilers ought to be smart enough to figure that one out!
Even in if tests the conversion is done:
void f(UINT8 value)
{
if (value == static_cast<UINT8>(2))
{
// do something
}
}
Could there be any logic behind this, because to me it looks like trying
to be smarter than the compiler, and perhaps even dangerous:
if you write this:
UINT8 Dummy = static_cast<UINT8>(-2);
the compiler will never complain, as it thinks you know better. But
maybe it's a typo, and this:
UINT8 Dummy = -2;
might at least give you a warning...
Can somebody enlighten me?
Thanks!
I'm currently using a lot of other people's code, and I kept stumbling
upon what looked to me as a 'weird habit':
In some general include dir there's a file with a bunch of typedefs like
typedef unsigned char UINT8; //!< 8 bits of unsigned integer
nothing wrong with that, I guess, but on every occasion where a type
like that is assigned, you see things like this:
UINT8 Dummy = static_cast<UINT8>(0);
I personally completely fail to see the logic in that...
I thought compilers ought to be smart enough to figure that one out!
Even in if tests the conversion is done:
void f(UINT8 value)
{
if (value == static_cast<UINT8>(2))
{
// do something
}
}
Could there be any logic behind this, because to me it looks like trying
to be smarter than the compiler, and perhaps even dangerous:
if you write this:
UINT8 Dummy = static_cast<UINT8>(-2);
the compiler will never complain, as it thinks you know better. But
maybe it's a typo, and this:
UINT8 Dummy = -2;
might at least give you a warning...
Can somebody enlighten me?
Thanks!