Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/lib/libarch/alpha



> On Thu, Mar 22, 2012 at 08:54:49AM +0000, Havard Eidnes wrote:
>> Module Name: src
>> Committed By:        he
>> Date:                Thu Mar 22 08:54:48 UTC 2012
>>
>> Modified Files:
>>      src/lib/libarch/alpha: alpha_pci_io.c
>>
>> Log Message:
>> Add a cast of the shift count to int32_t, so that we don't try
>> to do int32_t << long, since ANSI C doesn't perform "balancing"
>> before the shift operation according to lint.  Should not make a
>> difference, offset is limited to 0..3 anyway.
>
> Again, why is this needed or desirable? Both sides of the operator are
> unsigned, so in the worst case, promition happens to the wider of the
> type and the result is truncated immediately. The casts are yet again
> just making the code uglier.

The comment in lint says:

       /*
        * ANSI C does not perform balancing for shift operations,
        * but traditional C does. If the width of the right operand
        * is greather than the width of the left operand, than in
        * traditional C the left operand would be extendet to the
        * width of the right operand. For SHL this may result in
        * different results.
        */

and the corresponding warning from lint is

   semantics of '<<' change in ANSI C; use explicit cast

So that's what I did.

If you think lint is wrong, I encourage you to improve it.

IMHO, as long as lint is capable of helping us spot actual
problems, adding a few of these sorts of constrcucts seems like a
small price to pay.

Regards,

- Håvard


Home | Main Index | Thread Index | Old Index