Microsoft KB Archive/35471

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Unary Plus Operator Not Valid for Case Expression PSS ID Number: Q35471 Article last modified on 10-12-1988 PSS database name: S_QuickC




The unary plus operator causes the error message C2051 “Case expression not constant.” The expression works correctly with C Version 5.10. The unary plus operator was not expected in C compilers prior to the ANSI standard.

Microsoft has confirmed this to be a problem in Version 1.01. We are researching this problem and will post new information as it becomes available.

More Information:

The following source code demonstrates the problem:

  1. include <stdio.h>
  1. define Right_Way 1 #define Wrong_Way +2

void main() { int x; for (x= 1; x<3; x++) switch (x) { case Right_Way: puts(“This works”); break; case Wrong_Way: puts(“Get compile error”); break; default: puts(“Unknown”); } }

Copyright Microsoft Corporation 1988.