"Strong typing vs. strong testing"

Keith H Duggar duggar at alum.mit.edu
Wed Oct 6 19:50:10 CEST 2010


On Sep 29, 9:01 pm, RG <rNOSPA... at flownet.com> wrote:
> That the problem is "elsewhere in the program" ought to be small
> comfort.  But very well, try this instead:
>
> [ron at mighty:~]$ cat foo.c
> #include <stdio.h>
>
> int maximum(int a, int b) { return a > b ? a : b; }
>
> int main() {
>   long x = 8589934592;
>   printf("Max of %ld and 1 is %d\n", x, maximum(x,1));
>   return 0;}
>
> [ron at mighty:~]$ gcc -Wall foo.c
> [ron at mighty:~]$ ./a.out
> Max of 8589934592 and 1 is 1

$ gcc -Wconversion -Werror foo.c
cc1: warnings being treated as errors
foo.c: In function 'main':
foo.c:5: warning: passing argument 1 of 'maximum' with different width
due to prototype

It's called "learning to compile". And, yes, those warnings (and
nearly
every other one) should be enabled and treated as errors if a shop
wants
maximum protection. I only wish more (library) vendors did so.

KHD



More information about the Python-list mailing list