Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #96654

Re: Integer type extension and switch

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Integer type extension and switch
Date Tue, 15 Nov 2016 13:54:52 -0800
Organization None to speak of
Lines 39
Message-ID <lna8d0if2r.fsf@kst-u.example.com> (permalink)
References <326617a3-8f24-4110-8349-db7a0c17e7de@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="de46ff73fe43b8b35b0550d5525951b1"; logging-data="9452"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1p1FOVpCyQAEyx/VIHLIb"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:M9C8HRKL7BdeyCPyYIpeo0NqiNs= sha1:iCv/M4/HU+sQaDQ2k2vR0bsYyUc=
Xref csiph.com comp.lang.c:96654

Show key headers only | View raw


janus <emekamicro@gmail.com> writes:
> Why is the below not printing anything at all?
>
>   #include<stdio.h>
>   int main()
>   {
>           int a=10;
>           switch(a)
>           {
>                   case '1':
>                       printf("ONE\n");
>                       break;
>                   case '2':
>                       printf("TWO\n");
>                       break;
>                   defa1ut:
>                       printf("NONE\n");
>           }
>           return 0;
>   }

I suspect you're already aware that you misspelled the "default"
keyword.  "defa1ut:" is an ordinary label that could be used as the
target of a goto.

Strictly speaking there's no guarantee that '1' and '2' have values
other than 10, but they don't in any actual implementation I've ever
heard of.

It would have been more subtle if you'd written "defau1t".

An unrelated point: "int main(void)" is more explicit than "int main()"
and doesn't rely on an obsolescent feature.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Integer type extension and switch janus <emekamicro@gmail.com> - 2016-11-15 13:43 -0800
  Re: Integer type extension and switch Richard Heathfield <rjh@cpax.org.uk> - 2016-11-15 21:48 +0000
  Re: Integer type extension and switch supercat@casperkitty.com - 2016-11-15 13:49 -0800
  Re: Integer type extension and switch Keith Thompson <kst-u@mib.org> - 2016-11-15 13:54 -0800
  Re: Integer type extension and switch Ike Naar <ike@iceland.freeshell.org> - 2016-11-16 21:45 +0000
  Re: Integer type extension and switch "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-17 22:17 +0800

csiph-web