Why would somebody use an #if 1 C preprocessor directive?

Peter Smit picture Peter Smit · Feb 15, 2010 · Viewed 12.7k times · Source

I am looking through some C source code and I don't understand the following part

#if 1

   typedef unsigned short PronId;
   typedef unsigned short LMId;
#  define LM_NGRAM_INT

#else

   typedef unsigned int LMId;
   typedef unsigned int PronId;
#  undef LM_NGRAM_INT

#endif

Why would someone do #if 1? Isn't it true that only the first block will ever be processed?

Answer

James Curran picture James Curran · Feb 15, 2010

Yes.. Only the first block will be processed --- until someone changes the 1 to a 0. Then the other block will be compiled. This is a convenient way to temporary switch blocks of code in and out while testing different algorithms.