One of the lesser-known features of C++11 is the fact that you can overload your non-static member functions based on whether the implicit this object parameter is an lvalue reference or an rvalue reference by specifying a functions ref-qualifier. This feature works similar to the way cv-qualifiers work when specifying a method must be called on a const or volatile object, and can in fact be combined with cv-qualifiers.Continue reading →

In C++, there are two forms of binary operator overloading you can use when designing an API. The first form is to overload the operator as a member function of the class, and the second form is to overload the operator as a friend function of the class. I want to explore why you would use one form of overloading instead of the other, using a Fraction class as an example.Continue reading →

I recently read a post by Phillip Larkson where the C preprocessor was used to implement a four-bit adder entirely at compile time. This got me wondering whether I could implement the same concept using C++ template metaprogramming. It seemed theoretically possible as all the components can be calculated at runtime, but I wanted to avoid making use of the preprocessor for anything but supplying the original values to be added. The goal was to compile something on the command line like:

This code will print 12 instead of 13 because the expression ++a is unevaluated.

So what does it mean for an expression to be unevaluated? Basically, it means that the expression is used at compile time only as a way to determine a type, which is then used to evaluate the result of the sizeof operator. So in the above example, a’s type is determined, and the resulting type for ++ is determined, but no code is generated to execute the ++.

One of the lesser-known features of Visual Studio’s C/C++ compiler are the pointer type attributes __ptr32 and __ptr64. More information about them can be found on MSDN. These pointer type attributes are used to control the visible size and behavior of pointers in 32- and 64-bit applications. Their usage is a bit strange, but if you need to do interop between 32- and 64-bit mode, they can be handy features to have. Additionally, there are the __sptr and __uptr qualifiers which allow you to specify how the pointer types are extended. __sptr denotes sign extension, and __uptr denotes zero extension. Information about these qualifiers can also be found on MSDN.Continue reading →

Just because I’ve not written many posts lately doesn’t mean I’ve been silent. You should go check out the Tidbits page, it currently has over 20 little juicy pieces of information about C and C++. I’ve been using it as a training exercise for my coworkers, and it’s been very successful so far. I’ll likely be continuing with regular Friday updates of Tidbits for quite a while to come.

I do hope to write some more full-length blog posts now that life is starting to settle back down again. So I’m not dormant, honest!

Variable argument lists are very arcane in the world of C. You’ll see them expressed in function signatures as … at the end of the parameter list, but you may not understand how they work or what they do.Continue reading →

Some of us spend a fair amount of time pouring through crash dumps generated on Windows. For us, the symbol server support provided by Microsoft’s debugging engines is a godsend. However, source indexing is an even bigger boon because it allows us to not only see the symbols within the crash, but be able to pull the exact source down for source-level debugging.

Unfortunately, it seems that SVN 1.7 broke this functionality! Since it is so critical to my daily workflow, I set about fixing it.Continue reading →

You may have heard these terms used for various programming languages before, but I wanted to discuss them in a bit more detail since they’re a fairly fundamental concept in compilers that spill over into the way you use the languages themselves.Continue reading →

Who

Aaron Ballman is a security software engineer for CERT (a part of the Software Engineering Institute of Carnegie Mellon University). He has over a decade of experience writing cross-platform frameworks in C/C++, compiler & language design, and software engineering best practices and is currently a voting member of the C++ standards committee (WG21).

In case you can't figure it out easily enough, the views expressed here are my personal views and not the views of my employer, my past employers, my future employers, or some random person on the street. Please yell only at me if you disagree with what you read.