comp.lang.c
[Top] [All Lists]

Re: case labels

Subject: Re: case labels
From: "Bartc"
Date: Sat, 29 Mar 2008 02:12:43 GMT
Newsgroups: comp.lang.c


"Keith Thompson" <kst-u@xxxxxxx> wrote in message 
news:873aqapaog.fsf@xxxxxxxxxxxxxxxxxx
> CBFalconer <cbfalconer@xxxxxxxxx> writes:
>> "christian.bau" wrote:
>>> aark...@xxxxxxxxx wrote:
>>>
>>>> why are constant integer expressions required in case labels of
>>>> the switch statement? what would be the impact of allowing
>>>> general integer expressions instead of constant integer
>>>> expressions? discuss both user convenience and implementation
>>>> aspects?
>>>
>>> Consider
>>>
>>>   switch (i) {
>>>     case f (): printf ("f"); break;
>>>     case g (): printf ("g"); break;
>>>   }
>>>
>>> Discuss under user convenience, implementation, and general
>>> mental health aspects.
>>
>> The function f() is not a constant integer expression.  Illegal.
>
> Yes, of course it's illegal.  That's the point.  The example was
> intended to illustrate *why* it's illegal (beyond "because the
> standard says so").

Maybe I've missed something but how does this example show that it should be 
illegal?

I thought possibly all case values need to be considered simultaneously 
(difficult with variable expressions) but my C reference says nothing of 
this. It does say no two values can be the same (again not easy with 
variables), but this is an enhanced switch and the standard cannot cover it.

-- 
Bart 



<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy