C semantics changed

Yeah, I lost a full afternoon to find a bug that wasn't a bug but a change on how C handles NULL pointers. Basically, I was printing a NULL pointer, something you can test with a simple program like:
#include <stdio.h>
void main(void) {
  char *f = NULL;
  printf("%s\n", f);
}
Now... what should this code do? If you ask me before my war with C, I would say: it gives a nice segmentation fault. And in fact, it does, but for gcc 4.1.x. If you try with gcc 4.0.x or gcc 3.x, it prints "(null)". Now, when you suppose to have a string with "(null)" but you have not, and on some systems to print it really prints "(null)", can give you a big headache.

Leave a comment

About this Entry

This page contains a single entry by null published on March 25, 2006 2:57 PM.

The not so short introduction to LaTeX, PT version was the previous entry in this blog.

V for Vendetta is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.