2008-12-28

Spaghetti code? Meet lasagna and ravioli code!

An old joke, but a good one: http://www.gnu.org/fun/jokes/pasta.code.html

There are plenty more: http://www.gnu.org/fun/humor.html

And my favourite: http://www.gnu.org/fun/jokes/helloworld.html
However there is an ugly error, in the code they use void main():

New professional

#include <stdio.h>

void main(void)
{
char *message[] = {"Hello ", "World"};
int i;
for(i = 0; i < 2; ++i)
printf("%s", message[i]);
printf("\n");
}

This is non-standard (process returns a random number upon completion). It should rather be int main() instead - with a correct, standard behavior (process returns 0, even if final return 0; is omitted). Using void main() implies the dreaded "undefined behavior"...

No comments: