So that's why.
May. 11th, 2010 09:18 pmThis is an interesting read.
Roughly eight years ago, I had a project where I had to make a function, in C++, that traversed a tree. It was a fairly complicated project, a sort of really efficient way of packing geographic data so that you can find all the objects in a given radius, called a "bintree". The function that traversed the tree was long and hard to read through, and there was one very unlikely path through it that never actually hit a return statement. I ended up turning in the project late at about 2 AM, after having my roommate Bob help me debug it with a trick I've never forgotten.
But it always bothered me. The function was non-void. Why wouldn't the compiler at least give me a warning? It turns out, according to that page, that old C compilers didn't have a void type, so there was no way to make a function that didn't return a value. If you wanted that, the answer was to make a function with no return statement and just ignore the garbage "value". So, for compatibility with code written in this old style, new compilers don't complain about non-void functions that return void.
Roughly eight years ago, I had a project where I had to make a function, in C++, that traversed a tree. It was a fairly complicated project, a sort of really efficient way of packing geographic data so that you can find all the objects in a given radius, called a "bintree". The function that traversed the tree was long and hard to read through, and there was one very unlikely path through it that never actually hit a return statement. I ended up turning in the project late at about 2 AM, after having my roommate Bob help me debug it with a trick I've never forgotten.
But it always bothered me. The function was non-void. Why wouldn't the compiler at least give me a warning? It turns out, according to that page, that old C compilers didn't have a void type, so there was no way to make a function that didn't return a value. If you wanted that, the answer was to make a function with no return statement and just ignore the garbage "value". So, for compatibility with code written in this old style, new compilers don't complain about non-void functions that return void.