A while ago, I became interested in reducing my compile times, and examined various methods for this. This blog post is about enabling all compiler options that I believe can make gcc faster when compiling code, and measuring the gains I got as a result. How to Build It mkdir build-gcc16 cd build-gcc16 ../gcc-16.1.0/configure \ --prefix = ' $HOME /opt/gcc16-super' \ --program-prefix = super- \…
Virtual functions are one of C++’s core features, enabling runtime polymorphism. Most C++ programmers use them regularly, yet few understand how they work in practice. What does the compiler actually generate when you declare a function virtual ? How does the program figure out which implementation to call at runtime? Where is the vtable data actually stored? This blog post is focused on…
In C and C++ programs, it’s quite common to embed binary data directly in executables. Two straightforward ways are: // C23 #embed const unsigned char texture[] = { #embed 'texture.png' }; // Or xxd codegen'd array const unsigned char texture_png[] = { 0x89 , 0x50 , 0x4e , 0x47 , /* ... */ }; unsigned int texture_png_len = 12345 ; This is quite convenient. The data is now part of the…
This post explains exactly how UTF-16 encodes Unicode code points into bytes. If you haven’t read the history of how we got here, see The History of Text Encoding . From UCS-2 to UTF-16 Originally, Unicode was designed to fit in 16 bits - the Basic Multilingual Plane (BMP) , covering code points U+0000 to U+FFFF. The encoding UCS-2 simply stored each code point as a 16-bit integer. When…
This post explains exactly how UTF-8 encodes Unicode code points into bytes. If you haven’t read the history of how we got here, see The History of Text Encoding . The Design Goals UTF-8 was designed by Ken Thompson and Rob Pike with specific goals in mind: ASCII compatibility : Bytes 0x00-0x7F mean exactly what they mean in ASCII Self-synchronization : You can identify character boundaries…
Text encoding is a topic that not enough programmers understand well. It rarely appears on computer science curriculums, even at universities, yet it’s something almost every developer will encounter in the real world. It underpins every file you save, every message you send, every webpage you load. This represents a widespread and ongoing failure in programming education. When I first tried…
Recently, I was bored and decided to test the performance of a 4x4 matrix multiply. I wanted to compare how GCC and Clang optimize the same code with different flags. So I manually wrote a benchmark harness using a neat trick: a C file that’s also a valid shell script. The idea is simple. You embed shell commands in C comments at the top of the file. When you run sh benchmark.c , the shell…
I recently implemented BigObj COFF file parsing in cgo ( golang/go#24341 ). In the process, I quickly discovered that Microsoft doesn’t document the binary format anywhere. Their official documentation is the only reference they have to BigObj as far as I can tell, and it doesn’t say anything about the binary format. I didn’t see any other blogs or resources covering this topic…
When developing console applications, the Windows “Legacy Console” can be a handy tool. It behaves like the console present in Windows XP, allowing me to test how applications behave in this environment. This makes it simple to test compatibility, without having to painstakingly copy what I’m running over to Windows XP, and ensure it is compiled correctly for that target. When I…
In part 1 , we looked at how application developers can create a universal Vector2 type that converts to and from different library types. This approach works great when you control the application code, but what if you’re a library author? How can you design your Vector2 type to be automatically compatible with other libraries without knowing which ones your users might combine with yours?…
The Interoperability Problem When using multiple libraries in your project, a quite frequent source of annoyance is trying to share their fundamental types, such as a two dimensional vector, quaternion, euler angle, etc. In each library, you can find various names for exactly the same concept. Consider a hypothetical game development scenario: you could be using Box2D for physics (which has b2Vec2…
Cross compilation is a common task during development, but different compilers and programming languages handle it in their own ways, and I wanted to write about the various flavors of trade-offs and design decisions that you will find across different tooling. I feel like I have absorbed a lot of information about how cross compilation works across different targets, tools and languages, so I…
When executing various Makefiles with w64devkit , you can occasionally run across a Windows program with a Makefile written for cmd.exe. Often the only thing broken about them is the conventional clean target, which uses del.exe and will only work under cmd.exe . make clean del *.o /s sh: del: not found make: *** [Makefile:734: clean] Error 127 Confusingly, even if you then open cmd.exe and run…