Category Archives: C/C++

A simple introduction to type traits

Type traits are a slightly more advanced topic in C++ because it they are heavily used in template metaprogramming. However, it is not an impenetrable concept, and it comes with some great benefits if you like to write generic, reusable … Continue reading

Posted in C/C++ | Tagged , , | 11 Comments

An Almost Useful Language Extension

While fiddling around a bit with clang, I came across an interesting C++ language extension from Microsoft. If you’ve done library development on Windows, you’ve likely come across the __declspec keyword for things like importing and exporting symbols from a … Continue reading

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

Destructors

Destructors are one of those inescapable concepts in C++. We’ve all used them, many times without even really thinking about it. But how do destructors work? What can and can’t you do with destructors? There’s a lot more complexity to … Continue reading

Posted in C/C++ | Tagged , | 7 Comments

Switching on Expressions

The switch statement is a powerful construct in C that allows you to clearly express complex if/else if/else blocks as a single statement. By providing this construct, you can write code that’s easier to understand and maintain. The downside to … Continue reading

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

Virtual Inheritance

A question came up on LinkedIn in the C++ group relating to how virtual class inheritance actually works. Since LinkedIn limits the amount of space for responses, and also manages to screw up code formatting, I decided to tackle the … Continue reading

Posted in C/C++ | Tagged , , | 4 Comments

Virtual Methods and Multiple Inheritance

Previously, we covered the basics behind virtual methods. If you aren’t wholly comfortable with the subject yet, I’d recommend you go check that post out first. But if you are comfortable, we’re going to delve into the wacky fun world … Continue reading

Posted in C/C++ | Tagged , | 5 Comments

Virtual Methods

Virtual functions are a fairly well-understood programming construct in terms of how and when to use them. But have you ever stopped to think about how they actually work under the hood? You’ve probably heard the term “vtable” thrown around … Continue reading

Posted in C/C++ | Tagged , | 7 Comments

Static asserts

One of the new features of C++11 is the ability to do a compile-time assertions. These assert functions are similar in concept to the runtime assert functions we all know and love. You pass in a constant expression and a … Continue reading

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

Understanding Undefined Behavior

One of the harder concepts for people to understand in C++, in my opinion, is “behavior.” In C++, the language has some very specific wording for what the various behaviors are, and I’ve seen a lot of people get them … Continue reading

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

Preventing Evil Operator Overloading

While doing some research on allocators, I noticed that the language specification has some interesting wording with regards to getting the address of an element from an allocator. Specifically, it says (Section 20.6.9.1 Clauses 2 & 3): Returns: The actual … Continue reading

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