robert bristow-johnson said:
isn't it clear that when i run these lines of code:
a_short_array[26] = a_ulong;
printf("%d, %hx, %x, %lx \n", sizeof(a_short_array),
a_short_array[26], a_short_array[26], a_ulong );
256, d687, ffffd687, 12d687
that the bits in the hex digits "12" went bye-bye in the assignment
statement?
Yes. the C Standard does not require implementations to produce a
diagnostic message in this circumstance. A conversion is supplied. Of
necessity, if the lvalue is less wide than the rvalue, any information
stored in those extra bits will be lost. Nevertheless, the conversion
is a useful one in situations where no information is lost, and to take
advantage of it does not constitute a syntax error or constraint
violation, so no diagnostic message is required.
it just seems to me that this conversion qualifies as one that changes
value. then, according to the gcc doc, it should generate a -
Wconversion warning. it's close to an assignment of one type to
another but less severe. for example, if sizeof(unsigned
short)<sizeof(long) we know that no value is changed in this
assignment:
unsigned short a_ushort;
long a_long;
a_ushort = 4321;
a_long = a_ushort;
so no warning should be generated, no matter what bits are in
a_ushort, there is no change of value. whereas (assuming
sizeof(short)<sizeof(unsigned long)) this:
short a_short;
unsigned long a_ulong;
a_short = -4321;
a_ulong = a_short;
should generate a warning because there are values in the range of the
type (short) that are not in the type (unsigned long). so even if the
number of bits in the word are increasing in the assignment, this
should generate a -Wcondition warning (maybe it does, but it should
also do it for the original example i brought).
so i can see this warning as being functionally different from one of
type checking or even if there is a bit reduction. i just wish it
worked right.
Check in a newsgroup that deals with your implementation.
yeah, i should look for a gnu or gcc newgroup. just dunno where.
r b-j