Hacker News new | past | comments | ask | show | jobs | submit login

Confused, how does using unsigned integers not solve this particular problem? Doesn't the article itself show solutions with unsigned integers?



Example using 16-bit size_t for convenience:

  char array[60000]; // 5KB left for code and stack if not segmented
  size_t i = 40000;
  size_t j = 50000;
  size_t mid = (i+j)/2; // should be 45000
  // i+j = (size_t)90000 = 24464
  // mid = 24464/2 = 12232 != 45000
Larger integers make the necessary array size bigger, but don't change the overall issue.


Unsigned int is 32-bit, most address spaces are 48-bit or more.


Array.length is 32-bit in Java. This is from 2006.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: