In article <b1*************@ukato.freeshell.org>,
Nelu <sp*******@gmail.comwrote:
>ra***********@gmail.com writes:
> UINT8 MsgLength = 0;
>UINT8 does not exist in standard C. I will assume it is an 8 bit
unsigned int,
> MsgLength = strlen((char *)msg);
>strlen returns a size_t. In your case it will be converted to
UINT8, which may not be able to hold the number. If your string has
3000 characters size_t can hold it but UINT8 will not and the value of
the conversion is unknown.
Earlier, though, you assumed that UINT8 was an unsigned int (of some
particular size.) That being the case, for any particular value
integral returned by strlen, the conversion to UINT8 is well defined,
rater than the result of the conversion being "unknown".
"When a value with integral type is demoted to an unsigned
integer with smaller size, the result is the nonnegative remainder
on division by the number one greater than the largest unsigned
number that can be represented in the type with smaller size."
It happens that in a 2s complement system that this corresponds to
throwing away the upper bits and keeping only the bits that fit within
the smaller unsigned integer, but this value-based definition indicates
the value result for other representation systems as well.
In the example you gave, of 3000, then if UINT8 is 8 bits, the result
would be well defined as being 184 (3000 = 256 * 11 + 184).
Now, of course, if the strlen of msg happened to come out as 2816,
the result of the conversion would be 0 (2816 = 256 * 11), so this
property that the conversion result is well defined does not happen
to be a -useful- property for this code snippet...
--
Prototypes are supertypes of their clones. -- maplesoft