"Strong typing vs. strong testing"

ImpalerCore jadill33 at gmail.com
Thu Sep 30 15:48:51 EDT 2010


On Sep 29, 9:01 pm, RG <rNOSPA... at flownet.com> wrote:

<snip>

> [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

In the context of procedural programming, there is always an implicit
contract between the function and its client.  If you're going to fool
around sending cleverly crafted garbage into the input of 'maximum'
due to C conversion rules, why do you expect the 'maximum' function to
be responsible for producing the correct response to an ill-formed
question?  What alternative behavior of 'maximum' would you prefer to
see, that the C language auto-promote the function arguments and
return type to type long based on the type of arguments provided to
the 'maximum' function?

You either learn to play in the sandbox that C provides, splinters and
all, or you find another sandbox.

Best regards,
John D.



More information about the Python-list mailing list