C and Windows – Ouch!

05/26/2020 by Mike Honner

Filed under Programming

Last modified 06/04/2020

I programmed in C for Windows in the late 90’s. C programming for windows was very difficult. I had inherited a large Cash Management and General Ledger system (200k + lines of code) from the previous team. That team had not been trained in C and their previous work was Cobol programming for an IBM mainframe. They were great programmers, but brought over the the procedural programming practices to C. Functions were very long sometimes over 800 lines and used goto statements for flow control. The business logic was complicated and the programming was too. Without question, the most technically difficult assignment I’ve had outside of graduate school.

As any C programmer will tell you, the most powerful tool in C are pointers. C was a successor to Assembler and we could directly access memory, that is,  any location in memory could be directly addressed by using a pointer. You would them dereference the pointer and cast the value to an integer, float, double, struct or whatever value you knew it to be. And that was the hard part, you had to know the value type in the memory location you dereferenced to cast it. Make the wrong cast, and the application wold start doing strange things. Add to this the fact a pointer could point to a memory location that itself was a pointer, and things got confusing very quickly.

On the other hand, once I mastered pointers and dereferencing and set a standard for usage, the possibilities became endless. I had total control over the OS, and  I would frequently write generic functions that accepted arrays of pointers for financial processing like interest rate calcuations, daily cash sweeps from customer’s accounts to overnight lending institutions and printing to name a few.

The other challenge was programming for Windows. There were no tools for windows programming at that time and your code was native C against the Windows SDK. For those of use who programmed in C at that time, the notorious fatal dump “seg fault”, or segmentation fault was the bane of our existence. This got better with the introduction of Windows 95. Win95 forced all programs into their own segment, so if I made a programming mistake in the application it would only terminate my program, unlike the 16 bit version of Windows where a programming mistake in one program (usually overwriting memory in a location outside of you process) would end up in the dreaded blue screen of death.

I learned a great deal from that work, but was so happy to discover Java and the concept of the VM (Virtual Machine) where pointers, derefencing and memory management were abstracted away from the daily work of programming.

See what it took to write the famous Hello World program in C in 1995.

Related Articles