The Size Of Allocated Memory

In a comment on Google+ to my previous post The Size Of Strings, my colleague Lee Berg asked: Other than sizeof(), what is the best way to ensure a safe implementation? This is a damn good question because a built-in function to retrieve the size o… (read more)

The Size Of Strings

It's quite common to find pieces of C code like the following: void do_something() { const char foo[] = "This is foo"; ... func(foo, sizeof(foo)); ... } This is perfectly legal in C and, as you can try by yourself, s… (read more)

How C Compilers Work Part 4: Linker

Now we are at the point where we have produced one or more object files and we want to create an executable. Under GNU/Linux systems, this job is done by ld, the GNU linker. As seen in the previous part, the compiler always works on one file at once,… (read more)

Bitwise Right Shift With Signed Int

It's never too late to learn something new. And sometimes the compiler is smarter than what you think. In this case, I've discovered this behavior a couple of weeks ago while I was working on a C function that manipulates the bits of an unsigned inte… (read more)

How C Compilers Work Part 3: Compiler

The properly so called compiler is a really complicated piece of software. It performs many different tasks on single files. This means that no matter if your project is made of thousand source files: they will be compiled one by one. Now let's see t… (read more)

Horror Code: Paid By The Number Of Rows

The first thing I've thought is: "I'm missing something". But after few seconds the doubt that the author of the following code is paid for the number of lines of code come to my mind. Judge yourself: struct data_node *node = calloc(1, sizeof(*node))… (read more)

How C Compilers Work Part 2 - Preprocessor

As said in the previous post, in modern compilers, preprocessing is not a separate phase but it's made together with compilation. Nevertheless, understanding the role of preprocessor is really helpful. The first thing to say is that it basically unde… (read more)