Cool tricks!
About the debugging macros: printf prints messages to stdout, not stderr. You want to use fprintf instead:
fprintf(stderr ,"error message");
This has the advantage of being unbuffered, and still printing to the console even if stdout has been directed to a file.