way way back in first year a project was to write a text-based calculator in C++.
So, i busted out the program in a day maybe two using the STL stack implementation to do infix -> postfix conversion and statement execution. (then i got bored so added support for trig functions, square roots, absolute values and added constants eg e and pi)
anyway, the next assignment was to convert our C++ code into C.
so i hacked away and wrote a stack implementation in C, fairly easy, took me a few hours to iron out all the bugs (keep in mind i'd only learnt about pointers the day before
). Tested every minute detail of the stack, and it all worked perfectly
I implement the remainder of my program using this stack that i programmed.
It works perfectly, except for when i tried to compute any statement containing x*6 (eg (1*10^3+5)/(x*6))
it worked perfectly fine for statements containing 6*x (eg (1*10^3+5)/(6*x)) (where x is an element of the reals and where 6*x is within the bounds of a C double).
After spending a day tracing through the program in GDB i found that upon doing an x*6 calc, for some strange reason, it would always reset the 2nd bottom stack item to 0 when the 6 was popped from the stack (dont ask me why, to this day i have not got a clue).
Eventually i gave up on the problem and was looking through my code for any final revisions i could make. I noticed that id malloced some memory and not freed it, so i freed it up at the end of the program. Compiled, Ran one last test, decided to test the x*6 problem, and it worked
The memory i freed had _nothing_ to do with the stack, nor to do with the numeric processing. It was to hold some random snippet of user information so i have no idea why freeing it up fixed me problem.
So in conclusion: C, crazy stuff.