Zuhaitz Profile picture
Between 0s and 1s. C/C++ expert. Genius 🍅
Sep 8 7 tweets 3 min read
We know about malloc() and free() but they can be pretty slow. What if I told you there's a faster technique used for high-performance C programming?

Let's talk about Memory Arenas.

(Thread)Image What IS a memory arena?

A memory arena is a large, contiguous block of memory that you allocate once at the beginning of a task.

It's helpful because instead of using malloc() for each element, we can just work with our allocated memory.Image
Sep 6 7 tweets 2 min read
Ever noticed that when you use compiler optimizations (-O2, -O3), your program gets faster but the file size gets bigger?

This is not a paradox.

(Thread) Image The space-time trade-off

To make a program run faster, a compiler will often generate more machine code to save the CPU from doing work at runtime.

You are trading space (a larger binary) for time (faster execution).

Two common techniques that do this are function inlining and loop unrolling.
Sep 5 9 tweets 3 min read
Function pointers: this time you will understand them

(Thread)Image What IS a function pointer?

Just like normal pointers hold the memory address of a variable (like an int or a char), a function pointer holds the memory address of a function.

In C, when you compile your code, each function has its specific address in the executable memory.

A function pointer is simply a variable that points to that starting address.Image
Sep 2 6 tweets 3 min read
On June 4, 1996, the Ariane 5 rocket, carrying a payload worth half a billion dollars, exploded just 37 seconds after its maiden launch.

But what caused this? It wasn't a faulty engine or fuel leak. It was a single, uncaught software bug.

(Thread) Image A decade of work

The Ariane 5 was the European Space Agency's new flagship rocket.

After a decade of development and an investment of over $7 billion, its first flight was meant to be a triumph.

Everything seemed perfect, liftoff was flawless. For 30 seconds everything was nominal.But then the rocket suddenly veered violently off course, and triggered its self-destruct system.

You can watch what happened over here: youtu.be/PK_yguLapgA?si…
Sep 1 9 tweets 4 min read
Today we will talk about something different.

We will talk about Red Star OS, a North Korean operating system. I will show you how to bypass some possible issues and show some reverse engineering! Image The first thing we start with is the installation process. Surprisingly, it allows us to choose our location and timezone globally, which is already suspicious as it is a North Korean OS. Maybe it isn't completely. Image
Aug 29 7 tweets 3 min read
If you are learning C, you must have heard the word "compiler" endless of times. You know that it makes your code an actual program (a binary).

But how does it work? Let's explain it step by step with a simple hello world program!

(Thread) Image Let's say that, when we use the compiler, we usually go directly from the source file to the binary.

You can do this with (we will use gcc):

gcc hello.c -o hello

But we can go step by step with some specific flags! Image
Aug 27 20 tweets 12 min read
Want to learn C from scratch but don't know how?

Here I will provide you many of the concepts you will need!

(Thread) Image Let's start with something simple: variables & types.

C is statically typed, which means that you have to specify (declare) what the variable is.

Think of it like your HS physics teacher forcing you to write the units.

We have some key types: int, float, double, char. int is for integers; float and double for rational numbers; char for characters. Really straight forward.

If you want to learn more about types: geeksforgeeks.org/c/data-types-i…

[NOTE]: remember, sizes depend on architecture (for example: 32-bit vs 64-bit).Image
Jul 7 6 tweets 2 min read
Well, let's tall about the time I met Bjarne Stroustrup. I'll be honest, the man has some opinions. And they are exactly as based and unhinged as you'd hope for the creator of C++. Image His first gripe? How many "modern" C++ devs are still stuck in 2003.

"Why are they writing C++11 when we have C++20, C++23? All these amazing features, and they're still coding like it's 2003."

(To be fair, the whole conference was about the future of C++) Image