Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One of the very first IOCCC winners used the trick in 1984 (1984/anonymous):

    int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
    o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}


I think this is equivalent to:

    int i;
    int main(){
        for(
            ;
            i["]<i;++i){--i;}"]; // loop until i == 14? (the NUL byte on the end)
            read('-'-'-',i+++"hello, world!\n",'/'/'/') // read(0, <one byte of "hello, world!\n" at a time>, 1)
        ) {};
    }

    int read(j,i,p){
         write(j/p+p,i---j,i/i); // write(0/1+1, i-- - 0, 1) --> write(1, i, 1) --> write a byte to STDOUT
    }


what does this program do? i compiled it and ran it and got no output. i hope i haven't fork bombed myself or something


Prints "hello, world!", assuming sizeof(int) == sizeof(char*) (and the same alignments and ABI, etc).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: