[vox-tech] C question: global vs local const

Peter Jay Salzman vox-tech@lists.lugod.org
Thu, 17 Jan 2002 15:04:38 -0800


when ratio and K are defined externally, gcc complains about a
non-constant initializer:

   const double ratio = 2.0L;
   const double K = ratio;
   
   int main(void)
   {
      return 0;
   }

however, when defined as local variables, there's no problem.

   int main(void)
   {
      const double ratio = 2.0L;
      const double K = ratio;
   
      return 0;
   }

why isn't const being honored for the global variable version?

pete