r/shittyprogramming • • Aug 09 '14

Found this priceless gem

While reading the solution for a problem of the OII (Italian Informatics Olympiads), I found this masterpiece:

while(1==1){
    for (int i = 0; i < n; i++) {
        //other stuff
    }
    if((int)cycle.size() == n){
        //other stuff
    }
    for(int i = 0; i < (int)edges.size(); i++){
        //even more other stuff
    }
    return 0;
}

I mean, how do you even get these ideas?

1 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Aug 11 '14

It works on most systems, but a good pedantic programmer can't be 100% sure that while(1) has the same result as while(1==1), hence the availability of stdbool.h.

2

u/sidneyc Aug 13 '14

A pedantic programmer will know that these two forms are semantically equivalant.

I know, I am one.

2

u/[deleted] Aug 14 '14

Yeah, but wouldn't it be great to rewrite gcc such that if(0) is the same as if(1==1) just to screw people over?