Entries tagged “#c++”

Thu 22 November 2018

Bringing Visual Studio compiler into MSYS2 environment

Hi, Using Windows is a painful experience for a command-line oriented person like me. Unfortunately, Windows doesn't offer any decent command-line oriented environment, because well, it has different goals, and that's understandable. The problem is when one is forced to use Windows when it's clear that those goals are incompatible … read more
Wed 21 November 2018

Generating preprocessed sources in CMake projects

Hi, It appears you can use CMake to quickly generate preprocessed source of your chosen .cpp file without modifying the CMakeLists.txt project file. This trick works only when your generator is make -- meaning, it won't work with the ninja builder. But still, if you're using make as your generator … read more
Thu 01 March 2018

C++: Shooting yourself in the foot #3

Hi, Everyone says that programming is complicated. Is it? Well, actually it is, especially if you're using your programming language in a non-recommended way. Take file input/output for example. In C++ there are some ways you can perform file I/O: std::ifstream is one example. Multiple frameworks like … read more
Sun 11 February 2018

C++: Shooting yourself in the foot #2

Hi, There are people in this world who are forced to use C++ against their will. Those people often defend themselves by writing C code, and by compiling it with a C++ compiler. Then hope that noone will notice. There are a lot of problems with this, and this short … read more
Sat 20 January 2018

C++: Shooting yourself in the foot #1

Hi, Recently I was browsing some code, and I saw some construct that maybe is not very obvious to everyone. The code was located inside an important function, which took a hash in the argument and performed some action based on the contents of this hash. Pseudocode: typedef process_t { // ... uint8_t … read more
Mon 12 January 2015

Type-parametrized unit testing in GTest

Google's testing framework, GTest, goes beyond writing basic unit tests. It has some more advanced functionality that allows the user to cover more code with less tests, which -- considering the fact that unit tests always make a significant share of the source code ratio in a project -- is always a … read more
Thu 16 October 2014

Enabling globbing in a console Win32 application

"Globbing" can be also described as an act of expanding the filename wildcards supplied in the command-line of a console application. Let's suppose we have a small command-line application that performs some operation on files supplied as arguments in the command-line. #include #include int main(int argc, char … read more
Fri 12 September 2014

Sending ATA commands on Linux

It appears that any user can send an ATA message on Linux. The function that allows this is called ioctl, by using message identifier 0x31F (HDIO_DRIVE_CMD). It is possible to send, i.e. ATA IDENTIFY message by using 0xEC message. This command should return a device identification information. Other status … read more
Sat 12 July 2014

Emitting an event through an existing ETW provider

Let's assume a simple scenario. I have an application that uses native plugins. I have my own binary format for these plugins. Each plugin is loaded at runtime, using a method similar to mapping a DLL into the process' space. This means, each plugin has its own ImageBase, sections like … read more
Wed 02 July 2014

Control over symbol exports in MinGW linker

Below is an example on how to include, or exclude a symbol from the list of exported symbols in a DLL file. To test it out, we need to compile our object files first: C:\> g++ -O0 -gdwarf-4 dll\dllmain.cpp -c -o dllmain.o Linking is done by the … read more