Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I expect a good (programmer-friendly) compiler to at least warn the programmer in any case of provable, or potential, undefined behaviour

Should the following code have a warning? It has undefined behavior if argc == 0.

  int main(int argc, char **argv) {
      return **argv;
  }
As you can see, alerting for potential undefined behavior is a very difficult problem to do in a way that doesn't cause a bunch of spurious issues.

> refuse to compile/use implementation-defined behaviour (i.e. exactly "what the hardware does")

malloc is guaranteed to be 16-byte aligned on macOS. Should the following code not compile?

  void *memalign(size_t size, size_t alignment) {
  #if TARGET_OS_MAC
      if (alignment < 16) {
          return malloc(size);
      }
  #endif
      // General case
  }


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

Search: