/** * expt.h * Utilities for conducting experiments with code. */ #ifndef __EXPT_H__ #define __EXPT_H__ // +--------+----------------------------------------------------------- // | Macros | // +--------+ /** * BLOCK(CODE) * Turn CODE into a block that you can legally nest. */ #define BLOCK(CODE) do { CODE } while (0) /** * EXPERIMENT(COMMAND) * Print out command and then execute it. */ #define EXPERIMENT(COMMAND) BLOCK (fprintf (stderr, "%s;\n", #COMMAND); COMMAND;); /** * VAR_PREFIX * A prefix that should be put before printing any variable. */ #define VAR_PREFIX " // " /** * PRINT_INT(VAR) * Print the value of an integer variable. */ #define PRINT_INT(VAR) fprintf (stderr, VAR_PREFIX "%s = %d\n", #VAR, VAR) /** * PRINT_STR(VAR) * Print the value of a string variable. */ #define PRINT_STR(VAR) fprintf (stderr, VAR_PREFIX "%s = %s\n", #VAR, VAR) #endif // __EXPT_H__