Re: XMIN(size_t, ssize_t) ?

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Thu, 15 May 2008 14:44:04 -0600

On Fri, 2008-05-16 at 02:49 +0800, Adrian Chadd wrote:

> #include <stdio.h>
> #include <sys/types.h>
>
> #define XMIN(x,y) ((x)<(y)? (x) : (y))
>
> main()
> {
> size_t k = 4096;
> ssize_t l = -1;
>
> printf("min: %d\n", XMIN(k, l));
> printf("min: %d\n", XMIN(l, k));
> }
> violet:~ adrian$ cc test.c -o test
> violet:~ adrian$ ./test
> min: 4096
> min: 4096
>
> .. which explains the strange bugs that someone is seeing with Squid-2.HEAD
> and the store update stuff.

Interesting bug. FWIW, it looks like g++ automatically detects the above
error and says:
warning: comparison between signed and unsigned integer expressions

This probably means there are no such problems in Squid3 code except for
explicit casts. I do not know why gcc does not warn about these
problems.

Alex.
P.S. It looks like Squid3 XMIN replacement, being more conservative than
perhaps necessary, does not even let the above compile:
error: no matching function for call to ‘XMIN(size_t&, ssize_t&)’
Received on Thu May 15 2008 - 20:46:12 MDT

This archive was generated by hypermail 2.2.0 : Tue Aug 05 2008 - 01:06:35 MDT