Theory and Reality

One thing which I am pretty religious about is the placement of ++ and — in an expression. You have two options for where it can go. If it goes before the operand, it’s a pre-increment/decrement. If it goes after the operand, it’s a post-increment/decrement. They have different semantics, and so there are correctness issues with their placement. But what I want to talk about are the cases where there are not correctness issues, and what should happen.
Continue reading

Posted in C/C++ | Tagged , | Leave a comment

Memory Management in Frameworks

As a framework designer, you have a lot of things to worry about. Calling conventions, size compatibility, structure layout, etc. I’d like to briefly talk about another thing to worry about: memory management. I’m not just talking about “please don’t leak memory.” I’m talking about keeping a proper division of labor, and why it’s crucial for frameworks.
Continue reading

Posted in Framework Design | Tagged | 1 Comment

Describing the MSVC ABI for Structure Return Types

An ABI is an “application binary interface”, which is basically a contract between pieces of executable code on how to behave. The ABI dictates things like how parameters are passed, where return values go, how to create and destroy stack frames, etc. As a programmer, you oftentimes don’t have to worry about this sort of thing because the compiler takes care of it for you. However, if you want code from one compiler to talk to code from another compiler, the ABI is extremely important because if the two compilers don’t agree, the two pieces of code won’t be able to work together.

I don’t want to go into the entire MSVC ABI (that could likely fill a book!), but instead would like to focus on the under-documented portion having to do with the way structures are returned from functions. There is some documentation on the subject on MSDN, the latest of which can be found here.
Continue reading

Posted in C/C++, Win32 | Tagged , , , , | 6 Comments

The Anatomy of a Code Review

Programmers have many tools available to them for improving the quality of their code. One of my personal favorites is the code review — getting another set of eyes on my source code always challenges my assumptions, and invariably flushes out assumptions I’ve missed or mistakes I’ve made. I’d like to cover what I believe are the key elements to a successful code review. However, I would like to stress that what works for me may or may not work for you.
Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

Varargs? More like Arghargs!

This was a silly mistake on my part, but one which took me several hours to track down. In retrospect, I had everything at my disposal to tell me exactly what the problem was, I just didn’t notice it. It had to do with a varargs method pair for performing some logging operations. I had one logging method, and one helper logging method, both accessible to the caller. It turns out this was a bad idea.
Continue reading

Posted in C/C++ | Leave a comment

Worst Compiler Abuse Ever

I am pretty sure this qualifies as the worst abuse of a compiler I can think of. Note, I am not recommending you use this in production code, lest you wish to be set on fire by those who have to maintain or use your code. Yes, it is that bad.
Continue reading

Posted in C/C++ | Leave a comment

I Learned Something New About New

In my last post, I had mentioned that I found a phenomenon that made no sense to me. It had to do with initializing the members of a structure when calling new. Since I can’t let sleeping dogs lie, I went on an adventure to find my answers and I’d like to share what I found.
Continue reading

Posted in C/C++ | Tagged , , , | 1 Comment

Tail Calls

A tail call is a specific pattern of source code where the last instruction executed in a method is another function call. For instance:

int last( int i );
int second( int i );

int first( int i ) {
  int j = second( i );
  return last( j );
}

In this code, the call to last is considered a tail call because there are no further instructions to execute once the call is made.
Continue reading

Posted in C/C++ | Tagged , , | Leave a comment

Frustrations in Assembly

At my day job, we do a lot of complex math calculations in our frameworks. To increase performance, we have enabled the optimizer to use certain assembly instruction sets such as MMX and SSE. However, we have found that not all customers have processors which support these instruction sets. A while back, I added a simple CPUID check to the library initialization code to ensure the customer had SSE support on chip and I figured that was the end of that. I was wrong.
Continue reading

Posted in Uncategorized | Tagged , | 1 Comment

Lovely Holiday

I had a very nice holiday season this year, and I hope you did as well. My wife and I went down to TX to visit her family, and spend time lounging in a beach house. I didn’t write any blog posts while I was there because I was too busy playing Skyrim, fishing and eating copious amounts of delicious food. However, now that I’ve come crashing back to the realities of life, I’ll start blogging again.

Since it’s 2012 now, I figured it might be fun to reflect on what technologies I found important in 2011.

  • Visual Studio 2010 — it’s still my primary development environment, and nothing changed in 2011 to make me drift away. I do still pull out VS 2008, and XCode, as needed. But nowhere near as often as VS 2010.
  • Lint — this is a tool I’ve really come to love. It’s been around for ages and I’ve used it before, but not to the extent I have this past year. It’s helped me to solve a few gnarly bugs in existing code bases, as well as avoid bugs in new code I’ve been writing.
  • Steam — this was the first year I really used Steam a lot for gaming, and I must admit that I really like this approach. It’s trivial to purchase games, gift games, communicate with friends and overall just have a fun time. I sincerely hope more game manufacturers jump on the Steam bandwagon! This was the first year since I can remember that I didn’t purchase a single hard copy of a game. Everything was downloaded, and the vast majority of that was Steam.
  • Roku — my wife got me one for my birthday, and it definitely gets put through its paces. We use it to watch Netflix, Ted talks, BBC world news, listen to music and all sorts of great things. What I enjoy the most about it is how unobtrusive it is!
  • Windows 7 — Couldn’t live without it. I actually liked Vista, because I could see where it was going and wanted to get there. But Windows 7 is leaps and bounds ahead of Vista in terms of enjoyment to use. Which brings me to…
  • Windows Remote Assist — this feature is awesome. It is so incredibly easy to do screen sharing, remote control, etc. I use this application to perform code reviews with coworkers, help my brother-in-law learn C, fix problems on my mom’s computer, and it’s all painless.

And I can’t list the good without listing the bad as well!

  • MSDN — this was the first time since I can remember when I found myself using the web instead of my offline MSDN viewer. I’m not certain how I feel about this, since I did find myself writing code at airports without wifi a fair amount. But the quality of MSDN online is so much higher than the application, it just “happened” silently.
  • Soundblaster — when I built my new computer this year, I decided to put in a dedicated soundcard. I figured that on-board audio was sufficient, but I wanted to see if I could get a better experience (since I finally threw away my 10 year old speakers and got some 5.1 speakers to replace them). What a terrible idea. I haven’t gone as far as pulling the card out of the box, but I’m close. I get popping and clicking noises because of poor shielding, I get constant “oddities” where sound suddenly stops working because of poor drivers. And Creative has been pretty much useless in solving the problems.
  • MLB.com — when I got my Roku, I also got a subscription to MLB.com. It lasted less than 24 hours. I wanted to watch Twins games, since the local cable company dropped the channel which would televise them. But it turns out MLB.com will not allow you to watch games if you are in the viewing area — you must use cable. The only way around this would be to set up Tor or some other proxy (effectively) to mask my true location. Because who wants to watch their hometeam, right? That’s the last time I’ll bother trying MLB, NFL, or NHL’s online services.
  • Card Member Services — it’s this phone semi-scam operation that constantly robodials my work cell phone trying to get me to do some BS with a credit card. I’ve never had a professional dealing with these guys before, so what they’re doing is quite illegal. The FCC agrees, but can’t seem to shut them down. Trying to get off their calling list gets you hung up on, as does asking for supervisors. So I devised a more analog approach to the problem. I always get one of their live humans on the phone, talk to them for a minute, and then blow a gym whistle into my phone until they hang up. I hope someone’s eardrums bleed and they get worker’s comp for it.
  • Gaming consoles — for the first time in ages, I played far more video games on my PC than on any of the consoles I own. I don’t have a real explanation for this, but it’s caught my attention. I always used to dislike PC gaming because I missed the controller, and because I work from home, I liked getting away from the computer. But at some point this year, I stopped playing on my consoles. Perhaps it was because of how easy Steam is?

If you’d like to share your technology hits and misses, feel free! Otherwise, I hope you had a great 2011, and have an even better 2012 (unless the world ends because the Mayans were right :: snorts ::)!

Posted in Uncategorized | 2 Comments