Monday, January 3, 2022

Types of Makefile and build system

 Different type of Makefile

  • Default/legacy make file -> GNU Makefile
  • Cmake 
  • Autotool -> Makefile.am -> Makefile.in
  • Linux kernel special Makefile
  • Android.mk

Build system/tool

  • Ninja and Meson
  • Yocto
  • Cerbero

Friday, July 9, 2021

synchronization between kernel thread and ISR

Why we need volatile

 The volatile keyword is a type qualifier which tells compiler to not to optimize/cache any operation with these variable.


Value of this variable can change between two read or two write by external forces or event


The volatile keyword is mainly used where we directly deal with GPIO, interrupt or flag Register. It is also used with a global variable or buffer which shared between the threads.


some good program to be written in c or c++ programming

 - Write a program to Draw circle 

- Write a program for Matrix multiplication

- Write a program to reverse bitstream. (bit by bit reverse in  1 byte of data)

https://stackoverflow.com/questions/22004690/print-odd-and-even-numbers-using-2-threads-using-mutex-in-c



virtual memory, virtual base class and virtual function

 Virtual Memory

Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.

This enables a computer to be able to compensate shortages of physical memory by transferring pages of data from random access memory to disk storage.

More at https://www.geeksforgeeks.org/virtual-memory-in-operating-system/

Virtual Base class

When a class is made a virtual base class, C++ takes care to see that only one copy of that class is inherited regardless of how many inheritance path exits between the virtual base class and derived class.

Virtual function

This is example of runtime polymorphism


(Function overloading & Operator overloading are example of compile time polymorphism)

In c++ we can point any derived object via its base pointer.
But that pointer can not be used directly to access all members of derived class. by default that base  pointer will points to base class members only.

when we have same function name used in base class & derived class then if we mark base class function as virtual function then c++ decides which function to call at runtime based on the type of object pointed by base pointer. 

Pure Virtual functions

Its normal that we mark one function as virtual in base class and redefine it in derived class.

Many times virtual function in base class are just place holder and do nothing.

virtual void display() = 0;

such function called pure virtual function.

Such base class can not declare their own object.

so these classes are also called abstract base class.

sizeof operator implementation

 #define my_sizeof(type) (char *)(&type+1)-(char*)(&type)


This can not be implemented by function. For any function its argument
type needs to be always fixed.

Little and Big Endian

 Little and big endian are two ways of storing multibyte data-types.



Suppose integer is stored as 4 bytes then a variable x with value 0x01234567 will be stored as following in Big Endian

Big Endian:

  01,                   23,                45,             67

 0x100             0x101            0x102         0x103


Little Endian

 67,                   45,                23,             01

 0x100             0x101            0x102         0x103


Sample C program to check this.,


int main() 
    unsigned int i = 1; 
    char *c = (char*)&i; 
    if (*c) 
        cout<<"Little endian"
    else
        cout<<"Big endian"
    return 0;