0

In following code there is declaration even before the block beginning of the main function. Is this allowed?

long long n,u,m,b;
main(e,r)
    char **r; //<<<Is this possible???
{
    for( ; n++ || (e=getchar()|32)>=0 ; b="ynwtsflrabg"[n%=11]-e?b:b*8+n)
        for( r=b%64-25 ; e<47&&b ; b/=8)
            for( n=19; n ; n["1+DIY/.K430x9G(kC["]-42&255^b||(m+=n>15?n:n>9?m%u*~-u:~(int)r?n+!(int)r*16:n*16,b=0))
            u=1ll<<6177%n--*4;printf("%llx\n",m);
}

Source: I found this code on ioccc.org

Kurt Pattyn
  • 2,722
  • 2
  • 29
  • 40
mlemboy
  • 387
  • 3
  • 14

1 Answers1

6

Yes, C allows declarations outside of functions. These declarations define global or static variables (you need a static modifier for that).

Re-formatting your program produces this:

long long n,u,m,b;
main(e,r)
    char **r; // Pre-ANSI parameter declarations; do not do that in new programs!
{
    for( ; n++ || (e=getchar()|32)>=0 ; b="ynwtsflrabg"[n%=11]-e?b:b*8+n)
        for( r=b%64-25 ; e<47&&b ; b/=8)
            for( n=19; n ; n["1+DIY/.K430x9G(kC["]-42&255^b||(m+=n>15?n:n>9?m%u*~-u:~(int)r?n+!(int)r*16:n*16,b=0))
                u=1ll<<6177%n--*4;printf("%llx\n",m);
}

There's some serious obfuscation going on here, but syntactically it's valid code.

Sergey Kalinichenko
  • 697,062
  • 78
  • 1,055
  • 1,465