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


Groups > comp.lang.c > #96649 > unrolled thread

Integer type extension and switch

Started byjanus <emekamicro@gmail.com>
First post2016-11-15 13:43 -0800
Last post2016-11-17 22:17 +0800
Articles 6 — 6 participants

Back to article view | Back to comp.lang.c


Contents

  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

#96649 — Integer type extension and switch

Fromjanus <emekamicro@gmail.com>
Date2016-11-15 13:43 -0800
SubjectInteger type extension and switch
Message-ID<326617a3-8f24-4110-8349-db7a0c17e7de@googlegroups.com>
Hello All,

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;
  }

[toc] | [next] | [standalone]


#96651

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-11-15 21:48 +0000
Message-ID<o0fvqg$d1v$1@dont-email.me>
In reply to#96649
On 15/11/16 21:43, janus wrote:
> Hello All,
>
> 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;
>   }
>

There is no case matching the value of a (which is 10). On your system, 
presumably neither '1' nor '2' has the value 10.

If you were expecting the word NONE to be printed, I suggest you change 
your label from defalut: (which is just a normal label) to default: 
which has a special meaning to switch().

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#96652

Fromsupercat@casperkitty.com
Date2016-11-15 13:49 -0800
Message-ID<3ad9d82a-d3e6-413f-b764-925db4449137@googlegroups.com>
In reply to#96649
On Tuesday, November 15, 2016 at 3:43:42 PM UTC-6, janus wrote:
> Hello All,
> 
> 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;
>   }

In the character coding used by the program, neither the character '1'
nor '2' is represented by character code 10 (which in ASCII would be
a linefeed/newline, and would be unlikely to represent a digit in any
character set used by a C compiler).  The switch statement contains a
label defa1ut: that doesn't seem to be used for any purpose, but there
is no default: label.

[toc] | [prev] | [next] | [standalone]


#96654

FromKeith Thompson <kst-u@mib.org>
Date2016-11-15 13:54 -0800
Message-ID<lna8d0if2r.fsf@kst-u.example.com>
In reply to#96649
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"

[toc] | [prev] | [next] | [standalone]


#96717

FromIke Naar <ike@iceland.freeshell.org>
Date2016-11-16 21:45 +0000
Message-ID<slrn3vfso2pkso.cj.ike@iceland.freeshell.org>
In reply to#96649
On 2016-11-15, janus <emekamicro@gmail.com> wrote:
> Hello All,
>
> 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;
>   }

Because you wrote it that way.

[toc] | [prev] | [next] | [standalone]


#96735

From"Mr. Man-wai Chang" <toylet.toylet@gmail.com>
Date2016-11-17 22:17 +0800
Message-ID<o0ke4a$pv3$5@dont-email.me>
In reply to#96649
On 16/11/2016 5:43 AM, janus wrote:
> Hello All,
>
> Why is the below not printing anything at all?
>
>   #include<stdio.h>
>   int main()
 > ...

Any compilation errors?


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web