Article View: comp.std.c
Article #3634Re: Switch switch
From: Stephen Baynes
Date: Thu, 03 Aug 1995 07:38
Date: Thu, 03 Aug 1995 07:38
40 lines
1637 bytes
1637 bytes
Jim Fleming (jim.fleming@bytes.com) wrote:
: Has there been any consideration given to relaxing the type requirements
: for the C switch statement expression...???
: switch (<integral expression>){
: case <integral constant>:
: ...
: default:
: }
: Does anyone want to be able to write....???
: switch (aString) {
: ...
: case "hello":
: ...
: break;
: case "world":
: ...
: break;
: }
Think what happens in the following code:
char *s = something;
if( s == "abcde" )...
The only consistant extension to C to support you example would be to allow
pointers as values in switch statements. Your switch statment would then work
but not as you want because it would be comparing the addresses of the strings.
I suspect there are compilers out there that only give warnings for implicit
pointer to int conversions that will compile and run your example (with
lots of warnings) and will do it using pointer comparison.
--
Stephen Baynes baynes@mulsoc2.serigate.philips.nl
Philips Semiconductors Ltd
Southampton My views are my own.
United Kingdom
Technical Details
Message-ID:
<DCq58A.24L@ukpsshp1.serigate.philips.nl>Path:
arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynesReferences:
<3vn92m$oqt@News1.mcs.net>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!phcoms4.seri.philips.nl!panther!baynes From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) Subject: Re: Switch switch Sender: news@ukpsshp1.serigate.philips.nl (account for localnews) Message-ID: <DCq58A.24L@ukpsshp1.serigate.philips.nl> Date: Thu, 3 Aug 1995 07:38:34 GMT References: <3vn92m$oqt@News1.mcs.net> Organization: Philips Semiconductors, Southampton, UK X-Newsreader: TIN [version 1.2 PL2]