tech-userlevel archive

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

Re: Fixing lint warnings



> In fact, I believe the cast should *only* be added if it is intended to
> mark the implicit cast as potentially not value preserving.

And even then there are cases where casts are only confusing.
Consider the following:
        byte[0] = foo;
        byte[1] = foo >>= 8;
        byte[2] = foo >>= 8;
        byte[3] = foo >> 8;
which quite unambiguously convers a value to little-endian bytes.
It doesn't need any casts, nor any explict '& 0xff';

I would only add 'integer' casts where they are absolutely needed in order
to generate the required value. eg when you need a product that is
larger than 'int'.

Casts like *(int *)&foo ring massive alarm bells, so I'd rather the
number of casts be kept to an absolute minimum.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index