Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ellipsis in c's case statement?

CASE expr_no_commas ELLIPSIS expr_no_commas ':'

I saw such a rule in c's syntax rule,but when I try to reproduce it:

int test(float i)
{
switch(i)
{
  case 1.3:
    printf("hi");
}
}

It fails...

like image 371
assem Avatar asked Mar 16 '11 15:03

assem


1 Answers

OK, this involves a bit of guesswork on my part, but it would appear that you're talking about a gcc extension to C that allows one to specify ranges in switch cases.

The following compiles for me:

int test(int i)
{
  switch(i)
  {
  case 1 ... 3:
    printf("hi");
  }
}

Note the ... and also note that you can't switch on a float.

like image 125
NPE Avatar answered Sep 28 '22 09:09

NPE