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

Re: case labels

Subject: Re: case labels
From: "Bartc"
Date: Sat, 29 Mar 2008 00:04:55 GMT
Newsgroups: comp.lang.c

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.

-- 
Bart 



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