As Ken Thompson showed, you can never trust a compiler. His most famous example was of a trojan compiler, though he later refined the model. Lesser know is his example of the trojan-less compiler: it meets your sister in a bar, buys her a couple of drinks, and the next thing you know you've got a shotgun and a preacher. That's when the compiler skips town.


That, of course, is an extreme example; and as much as we all like extreme programming, it doesn't exactly reflect reality. Given a shortage of power drinks, you can often get less rowdy compilers to do what you want by speaking slowly and repeating key phrases. Realizing this, Anders sent in a perfect example, taken from a module loader.

  char * path = strdup(getenv("MODULE_PATH"));

/* ... */

while(path != NULL) {
  ptr = strchr(path,':');
if(ptr != NULL) {
*ptr++ = '\0';
   }
RegisterPath(CreateSymbol(path));
path = ptr;
} while (path != NULL);

See how easy that was? With only a few extra keystrokes, it was possible to convince the compiler that you take NULL very seriously.

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