Skip to content

Instantly share code, notes, and snippets.

View satyx's full-sized avatar

Satyam Sharma satyx

View GitHub Profile

The need of Header Files

Introduction

Almost everyone who has even written a hello world program in C/C++ must have used header files using the include directive (remember how you imported stdio.h or iostream.h or used custom header files). But why do we actually need header files? Obviously to use predefined libraries whenever we want and don’t have to write all the crap everytime we start using it. Hmm yes, that’s true, but do we really need a specific file for that, why can’t we simply import the .cpp/.c file wherever it is required, I mean that would entirely bring the body of the function in our source code, thus we can simply use it. The answer to this question might seem extremely obvious to some of us but let us try to explore the seriousness of it step by step.

Compilation

Anyone who has written even a simple makefile would know but for the sake of completion, compilation process consists of multiple steps:

  1. Preprocessor: First the preprocessor preprocesses all the code before compilatio

GNU Make : Guide for an absolute beginner

Introduction

How beautiful will it be, if there could be something which could save us from writing long commands for compiling our c/c++ projects. Like, build myDreamProject and Voilà! The executable is ready and your system itself took care of building all the necessary files, compiler flags, which compiler to use corresponding to each component … and the requirements are endless. Thanks to GNU MAKE, this is possible. Though it's syntax looks scary and beginners tend to skip it, with basic understanding it can literally be your best friend.

Probably you must have encountered a makefile if you ever went through any C/C++ project. Makefiles essentially contains all the rules to build target file(s). A proper makefile saves a lot of effort while building any project. Oh can't we use the divine knowledge of scripting? Well GNU MAKE only builds those files whose dependencies (referred as prerequisites) are modified, thus eliminating a redundancy and making your b

Pointers to Functions and Member Functions : Something you shouldn’t have seen-zoned

Introduction

Probably one of the biggest advantages as well as biggest source of vulnerability in C/C++ are pointers (if handled carelessly, of course). Unfortunately, this is usually aliased with the thought “used to access a variable indirectly i.e. access variable’s memory location” by the beginners, and misses (or seen-zones :P) out an entire dimension of dereferencing functions using pointers. In this blog, I will try to demonstrate magnificence of function pointers

Pointer to Functions

To start with, let's have a basic clarity, pointers can point to any virtual memory location (it’s accessibility is a different story, depending upon the type of memory). So crudely speaking, functions themselves are a set of instructions stored in a memory region which is accessed using a function identifier. Essentially the execution jumps to instructions stored at a different location (or should I say, the instruction pointe