Search code examples
c-preprocessorpreprocessor-directive

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


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?


Solution

  • 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.