-
Comment Toggle Trick
This is a neat comment toggle trick. When you have two path of mutually exclusive code of execution, do this to enable the first section. Remove the first back slash to comment out the first section and uncomment the second section.
-
Avoid Default Clause in Switch Case for Enum
Do not define a default clause for enum in switch statement! Say in future, if another fruit type is added to the enum, default clause shall cause the C++ compiler not to warn you that you have not handled the case for the new fruit. enum class Fruit { Apple, Orange }; Fruit fruit = […]
-
Private Inheritance
In private inheritance, the base class public access members are still public access in the derived class. Therefore the derived class still can call the base class functions and access its public data. But the user who instantiates the derived class, cannot access the public member of the base class, hence private inheritance. Public inheritance […]
-
Digitally Signing Without Worrying About Cert Expiry
If you want your executable’s signature to be still valid after certificate validity period, you have to digitally sign it with a timestamp from one of the timestamp websites with /tr switch before its expiry. In my case, I choose timestamp.digicert.com. This command is for Windows only. signtool.exe sign /tr http://timestamp.digicert.com /f Cert.pfx /p password […]
-
Size of a Empty Class with Virtual Function?
What is the size of the below class? struct MyClass { virtual ~MyClass(); }; The answer is size of a pointer(4 bytes or 8 bytes depending on the platform). That pointer is a vptr to vtbl of virtual functions. That being said, it is not a good idea to initialize a class consisting of POD […]
-
Avoid False Sharing With C++11 alignas Keyword
When two threads are frequently accessing and updating the 2 different but independent variables on the same cacheline, cache thrashing occurs as a result because when the thread updates its variable, the thread on another CPU core has its cacheline invalidated and have to fetch from the main memory again even though it is not […]
-
WiX: Escape Square Blanket
In WiX, property is referenced by enclosing its name in square blanket. For example, “[foobar]”. When a text (which we have no control over) is enclosed in blankets but is not a property, how do we escape it? This is not a WiX problem but a MSI method of deducing whether a value is a […]
-
Making HTTP REST Request in C++ With WinHTTP
WinHTTP Wrapper The example code is hosted at Github. The WinHTTP Wrapper consists of one main class that is HttpRequest class. In its constructor, the following parameters: user_agent, proxy_username, proxy_password, server_username and server_password are optional. When accessing the website through a proxy that needs logon, pass in the proxy_username, proxy_password to the constructor. Sometimes, the […]
-
C++: Faster to Retrieve Data By Ref Parameter or Returning a Ref?
In C++, there are two options to retrieve data from a object: either passing a reference parameter to be filled up or returning a reference. The former is making a copy of data (which may be what the developer wants) while the latter is returning a memory address of the data. The example code is […]
-
Direct2D Tutorial Part 4: Gradient Brush
Table of Contents Introduction Linear Gradient Rainbow Linear Gradient Rainbow Linear Gradient Text Radial Gradient Radial Gradient Text Demo Code History Articles in the Series The example code is hosted at Github. Introduction In this article, we’ll look at how to draw with linear and radial gradient colors in Direct2D. The prerequisite of the article […]