#ifdef and #define

Submitted by javelin on Tue, 2003-01-28 23:56

You can save yourself a lot of hassle if you're careful in how you hack the PennMUSH code. When you decide to add new code, or change old code, add an #define into options.h which will turn your code change on or off. For example, if you're adding a new feature to change the WHO format, put something like this into options.h:

/* If defined, the WHO commands will use a new format */
#define NEWWHO

Then, surround your additions with #ifdef NEWWHO...#endif pairs. For changes, use #ifdef NEWWHO...#else...#endif. For deletions from the original code, use #ifndef NEWWHO...#endif around the code to delete:

#ifdef NEWWHO
  this is code that you've added
#endif
...
#ifdef NEWWHO
  this is code you've changed
#else
  this is the original code
#endif
...
#ifndef NEWWHO
  this is original code you want deleted
#endif

This allows you to preserve the original PennMUSH coding, should you ever need to refer back to it (if, for example, you're trying to apply someone else's patch to something you've already changed), and allows you to turn on and off your feature as necessary.