Q:'default' before 'case' in 'switch'

Q:'default' before 'case' in 'switch'

Post by rad.. » Fri, 25 Jun 1999 04:00:00



Hi, all
Does anybody know whether this code

switch (x)
   {
   default: return 0;
   case 1 : return 1;
   case 2 :
   etc..
   }
is complient with the Standard?

It compiles (and executes OK) with MSVC++6.0
I haven't check other ones, but it looks a bit bothering to me

Thanx

--
rado
http:://members.tripod.com/~radosoft

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]

[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]

 
 
 

Q:'default' before 'case' in 'switch'

Post by Jack Kle » Sat, 26 Jun 1999 04:00:00



Quote:> Hi, all
> Does anybody know whether this code

> switch (x)
>    {
>    default: return 0;
>    case 1 : return 1;
>    case 2 :
>    etc..
>    }
> is complient with the Standard?

> It compiles (and executes OK) with MSVC++6.0
> I haven't check other ones, but it looks a bit bothering to me

> Thanx

<Jack>

The default and case keywords can be in any order whatsoever.  The
only limitations are:

Only one default.

No duplicate values in case statements, meaning the actual integral
constant which the expression evaluates to.

An implementation-defined maximum number of total case statements.

</Jack>
--
Do not email me with questions about programming.
Post them to the appropriate newsgroup.
Followups to my posts are welcome.

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]

[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]

 
 
 

Q:'default' before 'case' in 'switch'

Post by Jim Hyslo » Sun, 27 Jun 1999 04:00:00




> Hi, all
> Does anybody know whether this code

> switch (x)
>    {
>    default: return 0;
>    case 1 : return 1;
>    case 2 :
>    etc..
>    }
> is complient with the Standard?

Perfectly fine.  The Standard imposes no requirements on the order of
'default' and the constant expressions in the cases.

--
Jim
I ignore all email from recruitment agencies.
Please do not send me email with questions - post
here.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]

[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]

 
 
 

1. ListView problem capturing 'INS' and 'DEL' keys

Hey somebody!!

I'm trying to detect the 'INSert' and 'DELete' keys when a ListView has
focus.  What is the reccomended method?  I'm not using MFC.  I'm using a
traditional WndProc handler and my own C++ routines.

I trap a WM_NOTIFY message that seems to relate to the keys being depressed,
but I don't seem to be decoding the lParam properly.  I've been using the
'GetKeyState()' API call, but suspect that I'm doing something wrong.

So ..., what is the proper way to test for the 'INS' and 'DEL' keys when a
ListView has focus??  Thanks in advance.

***Carl

2. Registration

3. ListView Control: Inconsistency when switching between 'Icon View' and 'Report View'

4. VC++ binary data persistence in XML

5. 'initializing' : truncation from 'const double' to 'float' warning

6. Opening views with a specified subcategory

7. {'a','b','\0'} not equivalent to "ab"??

8. TreeView: what's the difference btw 'child' and 'sibling'?

9. File format for '.dll's' and '.lib'

10. 'const_iterator' : is not a member of '`global namespace''

11. What's the difference between '&' and '+'

12. 'Poke'ing and 'peek'ing other process's memory in VB6