Topic: Q:'default' before 'case' in 'switch
Author: jackklein@att.net (Jack Klein)
Date: 1999/06/25 Raw View
On 24 Jun 99 20:36:43 GMT, rado42@my-deja.com wrote in comp.std.c++:
> 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 ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Jim Hyslop <jim.hyslop@leitch.com>
Date: 1999/06/26 Raw View
In article <7ktavb$5dq$1@nnrp1.deja.com>,
rado42@my-deja.com wrote:
> 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 ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: rado42@my-deja.com
Date: 1999/06/24 Raw View
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 ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]