Martin v. Löwis added the comment:

Victor hinted that it would detect errors when combining int and unsigned int. 
To elaborate, see the attached min.c. It gives

[traditional MIN definition]
  [int, pointer]
min.c:18: warning: comparison between pointer and integer
min.c:18: warning: pointer/integer type mismatch in conditional expression
[static assert]
  [int, unsigned int]
min.c:20: error: size of array ‘type name’ is negative
  [int, double]
min.c:21: error: size of array ‘type name’ is negative
  [int, pointer]
min.c:22: error: size of array ‘type name’ is negative
min.c:22: warning: comparison between pointer and integer
min.c:22: warning: pointer/integer type mismatch in conditional expression

So compared to the traditional type checks:
a) this gives a hard compile error, whereas the existing check would only 
produce warnings
b) the existing min happily combines (int,unsigned) giving unsigned and (int, 
double) giving double; the new code will will reject such code.

I think the feature is somewhat desirable; I agree code combining different 
types in MIN or MAX is flawed - if it is intentional, asking for an explicit 
cast is not asking too much.

The only downside of the patch is that it uses a language extension. We should 
strive to reduce usage of language extensions, not increase it.

I also have a personal dislike of fanciness in code. Code should be clean, not 
cute.

----------
Added file: http://bugs.python.org/file26674/min.c

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15530>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to