The other day I complained that C# (prounced here as C-Pound) doesn't have macros. The author of today's example (uncovered by Stephen Ostermiller) was equally distraught over Java's lack of "unsigned addition." Of course, had our coder paid attention beyond first lesson in Computer Science 101 (in which he presumably learned about signed vs. unsigned binary representations), he would have discovered the wonders of twos complement binary representation (and the fact that computers represent integers this way). He then could have optimized his uintadd(x,y) method with "x + y".

/* Gotta love a language with no support for unsigned addition ... */
public int uintadd (int x, int y)
{
  long xL = ((long) x) & 0xffffffffL;
  long yL = ((long) y) & 0xffffffffL;
  long sumL = xL + yL;
  int sum = (int) (sumL & 0xffffffffL);
  return sum;
}
public int uintadd (int x, int y, int z)
{
  return uintadd(uintadd(x,y),z);
}
public int uintadd (int x, int y, int z, int k)
{
  return uintadd(uintadd(uintadd(x,y),z),k);
}

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!