I'm not sure whether to ask this question here or the C5000 forum. Anyway here goes:
The --check_32bit_int_portability switch is very useful for porting code from a standard architecture to the C5000 architecture where chars and ints are both 16 bits. It highlights code that would have worked on a standard architecture but not on the C5000, such as
short s1 = 10000;
short s2 = 600;
long bigNum = s1 * s2; // overflow on C55x
However it throws up many false positives that I think could easily be eliminated. I think the same warning is produced regardless of the binary operator on the last line.I think it should only warn if the operator can increase the number of bits that might be required to produce the result. To me this is just + - << and *, together with their corresponding assignment operators. I'd have to think real hard about it, but depending on the size and signedness of the operands, '-' may not be able to increase the number of bits either.
In other words I don't think it should warn for & | ^ >> / % or the comparison or equality operators. I haven't checked all of these but I know it warns for &, | and >>
I'm using v4.3.9.I've checked 4.4 and it does the same.
Can I put in a request for this enhancement please, or have I got this wrong?
I don't like ignoring warnings, because its easy to miss new ones when code is revised.
The only way to eliminate the warning I have found is to write another assignment expression which does the 16 bit operation, but I don't want to do that for an erroneous warning.
In some cases I can be sure from examining the code that there is no problem. With s1 and s2 as above:
long bignum = s1 + s2;
If I write instead
long bignum = (short)(s1 + s2);
in my view that should inform the compiler that I'm quite sure s1 + s2 won't overflow, and not to produce a warning. However I have to write
short s = s1 + s2
long bignum = s;
to eliminate the warning, which is overkill just to eliminate a warning.
So here is another request, a cast operator should have the same effect as the separate assignment and eliminate the warning.