| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"D" |
| Date: |
01 Dec 2004 01:09:16 PM |
| Object: |
switch statement |
Can a switch statement have an arithmetic attribute in it. For example
switch (x / 10)
{
case a: place your statements here
}
Thanks
.
|
|
| User: "Rob Williscroft" |
|
| Title: Re: switch statement |
01 Dec 2004 01:27:13 PM |
|
|
D wrote in news:d7d85b9a.0412011109.c229735@posting.google.com in
comp.lang.c++:
Can a switch statement have an arithmetic attribute in it. For example
switch (x / 10)
{
case a: place your statements here
}
No idea what you mean by "arithmetic attribute in it", if you mean
a non-compiletime-constant, then no.
int const ten = 10;
int main()
{
int x = 100, a = 10;
switch ( x / 10 )
{
case a: // illegal must be a compile time constant
case 10: // ok
case ten; // also ok.
}
}
HTH.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
.
|
|
|
| User: "Default User" |
|
| Title: Re: switch statement |
01 Dec 2004 04:20:28 PM |
|
|
Rob Williscroft wrote:
D wrote in news:d7d85b9a.0412011109.c229735@posting.google.com in
comp.lang.c++:
Can a switch statement have an arithmetic attribute in it. For
example switch (x / 10)
{
case a: place your statements here
}
No idea what you mean by "arithmetic attribute in it", if you mean
a non-compiletime-constant, then no.
Ah, you read it as asking about the case labels. I confess that now I'm
not clear what was meant. I took it to mean the controlling expression.
You're right, of course, about case labels.
Brian
.
|
|
|
|
|
| User: "Default User" |
|
| Title: Re: switch statement |
01 Dec 2004 04:17:02 PM |
|
|
D wrote:
Can a switch statement have an arithmetic attribute in it. For
example switch (x / 10)
{
case a: place your statements here
}
You mean expression, not attribute. The answer is yes, as long as the
expression yields an integer type. Assuming x is an integer type, then
your example above will have integer division and all will be well.
Brian
.
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: switch statement |
01 Dec 2004 01:28:03 PM |
|
|
D wrote:
Can a switch statement have an arithmetic attribute in it. For example
switch (x / 10)
{
case a: place your statements here
}
Yes.
V
.
|
|
|
|

|
Related Articles |
|
|