Category Archives: C/C++

Implementing a four-bit adder with C++ template metaprogramming

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 … Continue reading

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

Interesting Note About the sizeof Operator

The expression used in a sizeof operator is an unevaluated expression in C and C++. This can make for some surprising situations if you are unaware of it. For instance: This code will print 12 instead of 13 because the … Continue reading

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

MSVC Pointer Type Attributes

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 … Continue reading

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

How Variable Argument Lists Work in C

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.

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

Value Types in C++11

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 … Continue reading

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

Now, With More Tidbits!

Sorry about the distinct lack of content lately, but I’ve been busy putting together a new training initiative for my day job. This initiative involves sending weekly snippets of information on C and C++ to many of our developers. The … Continue reading

Posted in C/C++ | Leave a comment

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 … Continue reading

Posted in C/C++ | Tagged , | Leave a 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 … Continue reading

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

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 … 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 … Continue reading

Posted in C/C++ | Leave a comment