[lkml]   [1997]   [Sep]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Style question: comparison between signed and unsigned?

On Wed, 24 Sep 1997, Bodo Moeller wrote:

> Yes, you could run into problems. sizeof(...) has unsigned type
> size_t, while i is a signed int. Thus the comparison
> (i < sizeof(struct pkthdr))
> is equivalent to
> ((size_t) i < sizeof(struct pkthdr)),
> unless there was some clandestine change of the C standard. Here, the
> problem is not that sizeof(...) is converted to signed int, but
> that i is converted to an unsigned type. This could lead to undesired
> consequences if we hadn't already handled the case i < 0.

but the quoted example handled i<0 properly. If you want to warn about
_possible_ breakage, we would end up emitting a warning for every pointer
dereference ;)

it's just like the uninitialized varibale warning stuff. Compiler should
check wether i<0 is possible at that point, if yes, maybe emit a warning.

-- mingo

 \ /
  Last update: 2005-03-22 13:40    [W:0.035 / U:55.760 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site