View mode: basic / threaded / horizontal-split · Log in · Help
November 16, 2009
Re: About switch case statements...
Denis Koroskin wrote:
> BTW, if a macro was declared as
> 
> #define BASIC_TYPES            \
>          TOKwchar: case TOKdchar:        \
>     case TOKbit: case TOKbool: case TOKchar:    \
>     case TOKint8: case TOKuns8:        \
>     case TOKint16: case TOKuns16:        \
>     case TOKint32: case TOKuns32:        \
>     case TOKint64: case TOKuns64:        \
>     case TOKfloat32: case TOKfloat64: case TOKfloat80:        \
>     case TOKimaginary32: case TOKimaginary64: case TOKimaginary80:    \
>     case TOKcomplex32: case TOKcomplex64: case TOKcomplex80:    \
>     case TOKvoid
> 
> (note an absence of the first case) then it would cause compile-time 
> error instead of run-time bugs. Usage:
> 
> switch (token) {
>     case TOKidentifier:
>     case TOKenum:
>     case TOKstruct:
>     case TOKimport:
>     case BASIC_TYPES:
> }

I like that. Great suggestion!
November 17, 2009
Re: About switch case statements...
Derek Parnell wrote:
> On Mon, 16 Nov 2009 14:34:37 +0100, Don wrote:
> 
>> bearophile wrote:
>>> Don:
>>>
>>>> (providing that empty fall-through case statements remain valid; 
>>>> disallowing them would be really annoying).
>>> What's bad about forcing people to write:
>>> case A, B, C:
>>>
>>> Instead of:
>>> case A:
>>> case B:
>>> case C:
>>> ?
>>>
>>> Bye,
>>> bearophile
>> (1) "case A, B, C:" implies a relationship between A, B, and C, which 
>> might not exist. They may have nothing in common.
>> (2) it's an extremely common coding style in C, C++.
>> (3) it's more difficult to read.
> 
> (1)  case A:
>      case B:
>      case C:
>    implies that there is no relationship between A,B, and C, but which
> might actually exist. They may have something common.

Yes, of course! In which situation, you use case A, B, C:
I'm not arguing AGAINST that syntax, which already exists!

Your other two comments aren't worth responding to.
November 17, 2009
Re: About switch case statements...
On Tue, 17 Nov 2009 09:05:48 +0100, Don wrote:

> Your other two comments aren't worth responding to.

I apologize.  I also don't know what I said to offend you. I've taken steps
to make sure it doesn't happen again.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home