May. 11th, 2010

rbandrews: (Lambda)
This 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.

Profile

rbandrews: (Default)
rbandrews

July 2024

S M T W T F S
 123456
78910111213
14151617181920
212223242526 27
28293031   

Style Credit

Page generated Jul. 6th, 2025 10:21 pm
Powered by Dreamwidth Studios

Expand Cut Tags

No cut tags

Page Summary