473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

faq swith case can be a range?

Hi,
In swith statements, follow case is constant-expression, can it be a
range?
For example:
...
case ' 0 ' :
...
thanks.

Oct 16 '06 #1
5 4294

fcvcnet wrote:
Hi,
In swith statements, follow case is constant-expression, can it be a
range?
For example:
...
case ' 0 ' :
...
thanks.
No. Such a range is not an integral constant expression. Maybe you need
a chain of if-else if- ... -else.

Gavin Deane

Oct 16 '06 #2
Gavin Deane wrote:
>
fcvcnet wrote:
Hi,
In swith statements, follow case is constant-expression, can it
be a range?
For example:
...
case ' 0 ' :
...
thanks.

No. Such a range is not an integral constant expression. Maybe you
need a chain of if-else if- ... -else.
The usual way in C or C++ is to use "fall through".
switch (c)
{
case '>':
case '0':
// do stuff
break;
}
This quickly gets messy for large ranges, so using if-else if-else
ladders are prefered by many.


Brian
Oct 16 '06 #3
fcvcnet wrote:
In swith statements, follow case is constant-expression, can it be a
range?
It is a simple extension; BCPL, a C ancestor, had it in 1970, as in
case 'A' to 'Z':
If you are willing to use non-standard extensions, ask your compiler
vendor or get a public-source compiler and add it yourself.
Oct 16 '06 #4
Thanks you all.
Oct 17 '06 #5

fcvcnet wrote in message ...
>Thanks you all.
A litle slow on the draw here. I found this in the GCC docs:
"Case Ranges"

case 1 ... 5: // must be a space before and after the '...'

case 'A' ... 'Z':

May NOT be portable, GCC 'feature'.

The GNU crew is usually good about saying whether it is an GCC extension, ISO
C89, C90, C99. But, they didn't say in this case, so, try it in your compiler
and watch the error output. Maybe, report if it works in a compiler other
than GCC (It compiles in my MinGW 3.3).

--
Bob R
POVrookie
Oct 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
8
by: csanjith | last post by:
Hi, i have a situaion where i need to convert the characters entered in an text field to upper case using C. The configuration id utf8 environment in which user can enter any character (single ,...
11
by: Ola K | last post by:
Hi, I am pretty new to Python and I want to make a script that will search for the following options: 1) words made of uppercase characters -only- (like "YES") 2) words made of lowercase...
7
by: sam_cit | last post by:
Hi Everyone, In the following code, i have a common action for three switch cases, is there any other better way to write the three values in a single case? Thanks in advance #include...
2
by: JP2R | last post by:
The following is my code - I'm new to VB - not to Excel - just VB and need some support/guidance/direction (please) I have a spreadsheet and in column "X" titled COS I need to put an integer that...
4
by: Samuels90 | last post by:
Hey everyone, My program is supposed to go to Column R Row 2. If Column M contain "01" it should run the "sum(if array" for that Case,(no pun intended), in Column R. Can someone tell me what is...
2
by: RONSCHERER | last post by:
Hi. I write in VB. For some strange reason, throughout all the code written in one of my workbooks, the word "Range" had simply changed its case to "rANGE". eg: rANGE("C11").Copy ...
6
by: asit | last post by:
please modify to get the correct output.(switch case is compulsory) #include <stdio.h> int main() { char ch; printf("Enter any character : "); ch=getch(); switch(ch)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.