[cfe-users] curly brace position

Marshall Clow mclow.lists at gmail.com
Fri Jan 23 12:30:04 PST 2015


> On Jan 22, 2015, at 5:55 AM, Gri Msb <gri.msb at gmail.com> wrote:
> 
> Dear colleagues, I have found a strange bit of code that works, but I think it should not.
> 
> #include <stdio.h>
> int main ()
> {
>     int iC = 0;
>     for (iC = 1; iC < 5; iC++) {
>         switch (iC)
>             case 1:
>         { // Wrong?, but it works fine!.
>                 printf("ONE\n");
>                 break;
>             case 2:
>                 printf("TWO\n");
>                 break;
>             default:
>                 printf("NO!\n");
>                 break;
>         }
>     }
>     return 0;
> }
> 
> The code compiles without any warning using clang 3.4.1 (FreeBSD 10.1) and "-Wall" "--pedantic".  And the execution results are:
> ONE
> TWO
> NO!
> NO!

You might want to google “Duff’s Device”

— Marshall






More information about the cfe-users mailing list