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

Re: case labels

Subject: Re: case labels
From: Richard
Date: Mon, 31 Mar 2008 20:52:50 +0200
Newsgroups: comp.lang.c

"Bartc" <bc@xxxxxxxxxx> writes:

> christian.bau wrote:
>> On Mar 28, 5:48 pm, 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.
>
> No different to:
>
> if (i==f())
>     printf("f");
> else if (i==g())
>     printf("g");
>
> which is perfectly legal. It's a question of freedom of expression.

You need to think about the lines with or without break statements too
-this would then make the "else" incorrect. Do all the case functions
get execed or not? So no, in the absence of "case f()" being defined
nothing is obvious at all.


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