Mar 07, 2022

Compiling C programs

In previous tutorial we got a quick idea about C language. Today we are going to learn what is compiling programs and why it is needed.

As the first step let's see what's a computer program and how they handle the computer to do our needs. You know that computers only works with binary. Take this example. If we want to print "hello " to the screen we can write a program as this.

#include <studio.h>
int main(){
  return 0;

But computer can't understand this language. This is the time Compiler comes to play. Compiler will transform C code into mashing instructions. Mashing code is a set of simple instructions.

CPU can process simple instructions like move eax, esp / pop ebp/ push esp etc quickly.

If there is a instruction as move eax 0x00 CPU will move zero into eax register. Also if we say push esp CPU will take the value from ebp and push that on to top of the stack.

But even instructions like move eax 0x00 are not actual mashing language. It's something called Assembly language. So how CPU understand assembly ?.

There is a unique number for every assembly command. We call these hex numbers as Op-codes or operational codes.If opcode for move something into eax is 5f , opcode for move eax ,0x00 is 5f 00.

After converting these hex values to binary it will be something like '0000011000100100000011' Now CPU can understand what it says and quickly do that instruction. If we take long story shortly what happens hear is transform our C instructions into CPU readable mashing language. That's the job done by compiler. Now we have a clear idea about compiler and next see how we can compile C programs.

Compiling on a Linux mashing

If you are compiling a program on a Unix/Linux system, no additional software is needed. There is a awesome compiler called GCC for this.

You can easily open a shell and type

GCC -o [executable_name] [program_name.c]

GCC does rest for you. Now you can run it by entering ./program_name.

If you don't specify a name for executable file the default name will be a.out .

Compiling on a windows mashing.

In sometimes you may need to write C codes in windows environment. For a example if you are learning win32 exploit development then you want to write your own vulnerable codes for practice. So let's see how you can compile in windows. For this purpose you can use a compiler like dev c++. Dev compiler is a nice tool for compile and debug programs .

Now we can run the exe file.

Also you want a editor for write codes. You can use sublime , nano gedit or what ever you like. Personally I love sublime for coding.

OK guys. It's all for this tutorial. Thank you for reading.Don't forget to share it.C you again on next posts.

Apr 09
C programming array tutorial

In a previous article we discussed how we can declare and use variables in C. We know a variable is....

Jun 21
Protostar Stack1 Tutorial

In previous tutorial I completely explained how to exploit protostar stack 0 vulnerable program. In....

Aug 12
Get & Post | PHP tutorial

Today another tutorial on PHP programming. In this one I'm going to explain how we can fetch HTTP....

Replying to 's comment Cancel reply
Thilan Danushka Dissanayaka

Thilan Dissanayaka

Hi, I'm Thilan from Srilanka. An undergraduate Engineering student of University of Ruhuna. I love to explorer things about CS, Hacking, Reverse engineering etc.