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

Yes, patch is wrong (was Re: [XaraXtreme-dev] patch for warnings (3))

On 04/07/06, Alex Bligh <alex@xxxxxxxxxxx> wrote:
[ snip ]
> On Gentoo linux PPC (GCC4.1.1) I get several warnings where it seems
> that there is mixed char and int arithmetic.
> This patch shows the problem.

All these should do is cast EOF to "unsigned char" (or whatever "Ch" is).
Using hardcoded values is not nice. Alternatively, #define something
locally to be the casted version of EOF.

Sorry, I didn't mean to imply that I was presenting a satisfactory or
even a good solution. I 'm not even certain that any of these are
vivsible to anyone but me.

You are right that hard-coded or magic numbers should not be in source code.

Ch is a plain char (and is possibly doing the job of an int). Arguably
it should be an unsigned char (I use a typedef of Byte for 'raw
memory'), and the EOF symbol should be an enum

enum CH {
   /* ... */

or something similar - though if enums are the same size as ints, this
is not a win ...

So your last comment is also right.

I fear that all I was doing was pointing to a place where it looked as
though there was room for improvement, which is, as was stated by
journalist covering the famous Fisher-Spassky chess tournament, the
easiest job in the world.

All we need is for the code to be correct and look correct, doesn't
have to be perfect or all things to all men.