min/max and types

Eric Pouech eric.pouech at voila.fr
Wed Sep 19 02:21:20 CDT 2001


> > however, comparaisons like min(short, int) or min(size_t, DWORD) don't
> > provide lots of errors. integral promotions are straightforward, and
> > behave as expected by any programmer. so it would be rather ugly IMO
> > to write something like min((int)s, i) (s being short and i int)
> 
>    But in this last example, wouldn't it be better to declare s as an
> int or i as a short? Then we would not need a cast.
>    I believe we would rarely be forced to really compare integers of
> different sizes. Of course the only way to be sure is to really look at
> the actual warnings...
well, the warnings I looked at come of three kinds (for that's for from being exhaustive):
- comparing the dwSize of a struct with the sizeof of the struct. The first being a DWORD, the second of type size_t. Using the macro means using a cast here, which I find rather ugly
- comparing an unsigned int with an explicit integer : min(4, u). This could be rewritten easily into min(4u, u) for example
- real potential problems with comparing unsigned char with signed short for example.

IMO, the first two ones shouldn't require type casts.

last but not least, I think that the basic issue here is that gcc should report a sign mismatch in the comparison... and it doesn't. If it did, we wouldn't be arguing on the matter...

A+
> 
> 
> --
> Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
>      Linux, WinNT, MS-DOS - also known as the Good, the Bad and the Ugly.
> 
> 
> 
> 

---------------     
Eric Pouech 
(http://perso.wanadoo.fr/eric.pouech/)
The future will be better tomorrow, 
Vice President Dan Quayle


__________________________________________________
Voila vous propose une boite aux lettres gratuite sur Voila Mail:
http://mail.voila.fr







More information about the wine-devel mailing list