Unary Plus Operator Not Valid for Case Expression PSS ID Number: Q35471 Article last modified on 10-12-1988 PSS database name: S_QuickC
1.01
MS-DOS
Summary:
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:
- include <stdio.h>
- 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.