``Constants'' in case

Ian G Batten igb at fulcrum.bt.co.uk
Thu Sep 28 00:24:44 AEST 1989


Should this code fragment compile under (1) pcc (2) an ANSI compiler?

int x;

switch (x)
{
  case (int) 1:
   printf ("1\n");
   break;
  case (int) 2:
   printf ("2\n");
   break;
}

At least one compiler here rejects this, saying the case does not reduce
to a constant expression.  In fact, I suspect the general problem is
``is (int) constant a constant?''

ian



More information about the Comp.unix.wizards mailing list