C++ PImpl Template

less than 1 minute read

If you’re not familiar with the PImpl (private implementation) idiom, read this Wikipedia article first. While this is more or less “syntactic sugar” since the templates are expanded during compilation, but I think it makes for cleaner looking code.

Read 261 more words...

C Bitwise Operations Cheat Sheet

1 minute read

Operations Table

Operation Sample C Operator
AND 1001 AND 0101 = 0001 & (ampersand)
OR 1001 OR 0101 = 1101 | (pipe)
NOT NOT 1001 = 0110 ~ (tilde)
XOR 1001 XOR 1011 = 0010 ^ (caret)
LEFT-SHIFT LEFT-SHIFT 0001 BY 1 = 0010 <<

C Assignment Operators

Operation Syntax Short For
AND X &= Y; X = X & Y;
OR X |= Y; X = X | Y;
XOR X ^= Y; X = X ^ Y;
LEFT-SHIFT X <<= Y; X = X << Y;
RIGHT-SHIFT X >>= Y; X = X >> Y;

Read 287 more words...

C Tutorial 01: Hello, World!

7 minute read

If you ask a programmer which programming language you should learn as your first, they’ll often prescribe you their personal favorite, often not considering if the language is supported on multiple platforms, easy to learn, exposing underlying system mechanics, and fully featured.

This post is the first of a series of tutorials intended to teach you the C programming language, an excellent first language because of the following reasons:

Read 1,667 more words...

Creating a Window Wrapper Class: Redux

4 minute read

Okay, so I know you’re probably here because you searched for “window wrapper class” or something similar and expected the article that I use to host on Scriptionary that threw a bunch of C++ code at you for you to copy and paste. I regret to inform you that the article you were looking for has ceased to exist.

Sorry about that.

However, in its place I have for you this very post which will teach you how to accomplish creating such a wrapper all by yourself. I hope that is okay since all you really need to know is the how to create a window procedure that you can use with your custom class.

Read 1,043 more words...

A High-Resolution Timer for Win32

2 minute read

This post lists the code for creating a high resolution timer for the Microsoft Windows platform. High resolution timers are often used in multimedia and entertainment applications for timing events up to the microsecond.

This is a heavily modified re-post of the article that used to be on the Scriptionary.com website before the change to the blog, read the source code for details.

Read 705 more words...

Amount of Digits in an Integer

1 minute read

Here’s another little snippet that might come in handy in your programmatic travels. I’ll show you an example of usage below, which might also be of interest to you. The code presented is in C, not C++. First, the code to count the amount of digits in an integer:

Read 498 more words...

Flattening Multidimensional Arrays

1 minute read

Edit: Thank you, fixitman for the insightful comment; the code has been fixed to work with non-square arrays as well.

In an effort to produce a better performing multidimensional array, I would like to share the following with you. Say we have a Matrix (or multidimensional array) of 5 x 5 integer elements, M. In order to allocate such an array in C++, we use the following code:

Read 489 more words...

CriticalSection wrapper class

2 minute read

2023 Update: You probably don’t want to use this code since there are likely some serious issues with it. But, fun fact: a major tech company reached out to me to clarify what the license for this is. So, if you want to screw yourself over and use it, let’s say it’s MIT licensed and call it a day.

What: A C++ wrapper around both WINAPI (Microsoft Windows) and PThreads (POSIX threads) functionality.

Why: To abstract cross platform functionality.

Remarks: On windows, CRITICAL_SECTION objects cannot be shared cross-process. This means that the class is tied to your application or DLL process. Comments are in Doxygen/Javadoc style.

Read 568 more words...

Bitwise Programming in C

6 minute read

This article explains Bitwise Programming in C, a common practice in most programming languages. While bitwise operations might seem like a dark art at first, it really isn’t that scary. You simply need to know when to apply these operations and for what reasons to use them.

The article discusses bits (calculation, workings) in section one previous to the actual operators so that an understanding is made on how bits operate.

Read 1,589 more words...