c/2534: const int variables in case label

bug1@optushome.com.au bug1@optushome.com.au
Wed Apr 11 02:56:00 GMT 2001


>Number:         2534
>Category:       c
>Synopsis:       const int variables in case label
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 11 02:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     bug1@optushome.com.au
>Release:        unknown-1.0
>Organization:
>Environment:
gcc version 2.95.3 20010315 (Debian release)
>Description:
Why cant case lebels use const int variables ?
or
When is a cont int not a const int ?

This behaviour has been around for a while, so i assume its intentional,
 but i just cant understand why, it doesnt make sense to me.

I could #define one 1, but i preferable to avoid using defines as they dont do type checking.

Why not allow a const int to be used in case labels ?
>How-To-Repeat:
Compile this gives 
test.c:6: case label does not reduce to an integer constant
int main()
{
    const int one = 1;
    int value = 1;
    switch (value) {
        case (one):
            break;
        default:
    }
    return
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list