473,326 Members | 2,090 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,326 software developers and data experts.

case labels

Hi,

why general integer expressions are not allowed in case labels in
switch statements..????
Mar 28 '08
55 3080
Chris Dollin wrote:
CBFalconer wrote:
>"christian.bau" wrote:
>>aark...@gmail.com wrote:

why are constant integer expressions required in case labels of
the switch statement? what would be the impact of allowing
general integer expressions instead of constant integer
expressions? discuss both user convenience and implementation
aspects?

Consider

switch (i) {
case f (): printf ("f"); break;
case g (): printf ("g"); break;
}

Discuss under user convenience, implementation, and general
mental health aspects.

The function f() is not a constant integer expression. Illegal.

Chuck, that's a completely missing-the-point answer; we /know/
that `f()` isn't a CIE.

You've been doing this sort of thing a /lot/ recently. I don't
know why, so my proposed solutions -- re-read before posting,
cut back on threads, coffee control, loud prog rock during
commute -- may not work for you.
I just looked. The quotes in my answer (repeated above) contained
the entire article to which I was replying. At this moment this
thread contains 65 entries, only some of which are available for
reading. Some are mislinked. Why should you expect me to review
an entire thread (which may be impossible, this is Usenet) before
making a reply? My usage makes 'impossible' more likely than for
most. I based the reply on what I read (and I concede it is
possible to read that somewhat differently).

Since I gather the originator knew he was suggesting an
illegitimate construct, then the obvious comment is that so
implementing would prevent generating a fixed transfer buffer with
one entry per case. This is normally the most efficient way of
implementing a switch. We might as well eliminate switch and just
rely on if/else if/else.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Apr 1 '08 #51
CBFalconer wrote:

<snip>
We might as well eliminate switch and just
rely on if/else if/else.
Simulating a Duff device with if/else is very ugly.

Apr 1 '08 #52
CBFalconer said:
Chris Dollin wrote:
>CBFalconer wrote:
>>"christian.bau" wrote:
aark...@gmail.com wrote:

why are constant integer expressions required in case labels of
the switch statement? what would be the impact of allowing
general integer expressions instead of constant integer
expressions? discuss both user convenience and implementation
aspects?

Consider

switch (i) {
case f (): printf ("f"); break;
case g (): printf ("g"); break;
}

Discuss under user convenience, implementation, and general
mental health aspects.

The function f() is not a constant integer expression. Illegal.

Chuck, that's a completely missing-the-point answer; we /know/
that `f()` isn't a CIE.

You've been doing this sort of thing a /lot/ recently. I don't
know why, so my proposed solutions -- re-read before posting,
cut back on threads, coffee control, loud prog rock during
commute -- may not work for you.
<snip>
Why should you expect me to review
an entire thread (which may be impossible, this is Usenet) before
making a reply?
Why should you expect to be able to make an *intelligent* contribution
without reading at least a large part of the articles in the chain from
the root article to the one you're replying to?

The person to whom you replied is Christian Bau. Not J Random Lamer, but a
person whose name you ought to recognise as someone who knows his C.
Therefore, whilst it is *possible* that he might make a simple mistake
such as using a function call as a label, it is surely more likely that he
is making a point, by example, about the language (as in fact he was, in
this case).

When one shoots from the hip, one tends to hit the wrong target.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 1 '08 #53
Richard Heathfield wrote, On 01/04/08 07:19:
CBFalconer said:
>Chris Dollin wrote:
>>CBFalconer wrote:
"christian.bau" wrote:
aark...@gmail.com wrote:
>
>why are constant integer expressions required in case labels of
>the switch statement? what would be the impact of allowing
>general integer expressions instead of constant integer
>expressions? discuss both user convenience and implementation
>aspects?
Consider
>
switch (i) {
case f (): printf ("f"); break;
case g (): printf ("g"); break;
}
>
Discuss under user convenience, implementation, and general
mental health aspects.
The function f() is not a constant integer expression. Illegal.
Chuck, that's a completely missing-the-point answer; we /know/
that `f()` isn't a CIE.

You've been doing this sort of thing a /lot/ recently. I don't
know why, so my proposed solutions -- re-read before posting,
cut back on threads, coffee control, loud prog rock during
commute -- may not work for you.

<snip>
>Why should you expect me to review
an entire thread (which may be impossible, this is Usenet) before
making a reply?

Why should you expect to be able to make an *intelligent* contribution
without reading at least a large part of the articles in the chain from
the root article to the one you're replying to?
In this case it only required reading the quoted material where the
question "why are constant integer expressions..." Given that question
it is perfectly reasonable that people would post "invalid" C code to
show what the problems would be if this rule did not apply.

<snip good point>
When one shoots from the hip, one tends to hit the wrong target.
When one shoots from the hip at someone who is obviously not a valid
target there is no possibility of hitting the correct target. This,
obviously, is aimed at Chuck not RH.
--
Flash Gordon
Apr 1 '08 #54
On Fri, 28 Mar 2008 14:00:05 +0000, Chris Dollin <ch**********@hp.com>
wrote:
Eric Sosman wrote:
If you switch on a `char*', should the matching
criterion be strcmp()? Or caseInsensitiveStrcmp()? Or
allWhiteSpaceCountsAsIdenticalStrcmp()?

strcmp. If the user wants something else, they can canonise
their switched string first. (And I'm imagining a `strhash`.)
Canonicalize. I don't want strings I have to worship.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Apr 7 '08 #55
David Thompson said:
On Fri, 28 Mar 2008 14:00:05 +0000, Chris Dollin <ch**********@hp.com>
wrote:
>Eric Sosman wrote:
If you switch on a `char*', should the matching
criterion be strcmp()? Or caseInsensitiveStrcmp()? Or
allWhiteSpaceCountsAsIdenticalStrcmp()?

strcmp. If the user wants something else, they can canonise
their switched string first. (And I'm imagining a `strhash`.)
Canonicalize. I don't want strings I have to worship.
Presumably you are referring to St Ring?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 7 '08 #56

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

Similar topics

3
by: Martin Magnusson | last post by:
I'm using enums as case labels throughout my code, and that works fine in gcc 3.3.4. However, when compiling it with the compiler that ships with Dev-C++ 4.9.8.0, I get the error "case label does...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
3
by: Grim Reaper | last post by:
I print mailing labels out of Access 2000 databases about 3 to 4 times a week. I have been having problems with one thing since I have been printing mailing labels. I print mailing labels by...
3
by: Grim Reaper | last post by:
I know this is probably an easy question, but I could not find/figure it out. Basically, I am printing mailing labels with a "Sorting/Grouping" section that groups the label types together....
5
by: Frederick Dean | last post by:
Hi,guys! I'm reading Stephen Dewhurst's book "C++ Gotchas"£¬in gothca #7, I meet a weird case: bool Postorder::next() { switch (pc) case START: while (true) if (!child()) { pc = LEAF; return...
6
by: Ron | last post by:
Hi, I know Access allows for easy construction of a report setup to print labels from a table/query, etc. I've done that one. It works pretty well for what I need. However, is there an...
0
by: Zytan | last post by:
I want other labels in the task list such as DEBUG, but then when I comment out Debug.WriteLine, it appears in the task list. Is there anyway for it to be case sensitive? Right now, it's almost...
22
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point...
9
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to how a switch case like the following one is converted into a jump table by the compiler, assuming that it does, switch(i) { case 4 : { ... printf("4");
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.