report at bugs
Aug 3, 2012, 5:15 AM
Post #7 of 15
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]
min.c:18: warning: comparison between pointer and integer
min.c:18: warning: pointer/integer type mismatch in conditional expression
[int, unsigned int]
min.c:20: error: size of array ‘type name’ is negative
min.c:21: error: size of array ‘type name’ is negative
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 <report [at] bugs>
Python-bugs-list mailing list