This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Relaxing -Wsign-compare



   On Thu, Sep 20, 2001 at 03:45:27PM -0000, Morten Welinder wrote:
   > Would it be reasonable to silence this warning when one of the sides is
   > a constant (in the C meaning) that fits well within the range of the
   > other side's type?

   No.

Dang.

   C type rules still mandate the promotion of the signed argument to
   unsigned.  Which means that if you do not know for a fact that the
   signed argument is non-negative, you still have a problem.  Which
   you can't know without data-flow analysis, and the warning is based
   simply on the existance of the promotion.

Ok, thanks.

   Make 'i' a size_t like it ought to have been in the first place.

That's a very popular non-solution.  Normally the index value is
actually used, like for example:

for (i = 0; i < sizeof (foo) / sizeof (foo[0]); i++)
  printf ("%d\n", i);

With "int", the program is perfectly fine and portable.  With "size_t",
it isn't, if I understand things right.  There's no guarantee that "%d"
matches size_t.  Having to cast i when used is not appealing.

I guess an isizeof macro is my solution.

Thanks all!

Morten


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]