Best search algorithm to find condition within a range

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Apr 9 12:15:21 EDT 2015


On Fri, 10 Apr 2015 01:34 am, Chris Angelico wrote:

> It's equally impossible for the addition of two positive signed
> integers to result in a negative integer.

Why oh why do C programmers tell such porkies??? *semi-wink*

[steve at ando c]$ gcc add.c
[steve at ando c]$ ./a.out
a = 1
b = 2147483647
a+b = -2147483648


Looks like a negative integer to me, but then, given that its undefined
behaviour, perhaps the compiler flipped some pixels on the screen so it
merely *looks* negative.


Here's the source code:

[steve at ando c]$ cat add.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int a;
  a = 1;
  int b;
  b = 2147483647;
  printf("a = %d\n", a);
  printf("b = %d\n", b);
  printf("a+b = %d\n", a+b);
  return 0;
}



-- 
Steven




More information about the Python-list mailing list