On Tue, 18 Sep 2001, eric pouech wrote: [...]
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...
-- Francois Gouget fgouget@free.fr http://fgouget.free.fr/ Linux, WinNT, MS-DOS - also known as the Good, the Bad and the Ugly.
(resent because of mail issues)
still thinking about it, there is however some points I don't like (and especially for keeping it permanent) errors we want to catch are mainly related to sign mismatch (like min(char, unsigned short)...)
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)
on the other hand, in the case of min(char, unsigned short), only experienced programmers are able to tell the order of integral promotions involved here, and we really do need some guidance here. unfortunately, I don't see any ways not to let the min/max macro only spit errors on integral type of same sign-ness
A+-- --------------- Eric Pouech (http://perso.wanadoo.fr/eric.pouech/) "The future will be better tomorrow", Vice President Dan Quayle
On Thu, 20 Sep 2001 21:03:20 +0200, eric pouech eric.pouech@wanadoo.fr wrote:
(resent because of mail issues)
still thinking about it, there is however some points I don't like (and especially for keeping it permanent) errors we want to catch are mainly related to sign mismatch (like min(char, unsigned short)...)
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)
on the other hand, in the case of min(char, unsigned short), only experienced programmers are able to tell the order of integral promotions involved here, and we really do need some guidance here. unfortunately, I don't see any ways not to let the min/max macro only spit errors on integral type of same sign-ness
Another argument in the L-K debate was that precisely the same problem exists when comparing variables... and comparisons are much more common then min/max. One person suggested a LE/GT/etc set of #defines to capture those errors. Not an easy job.
john