Blog Archives

Rtags completes Emacs

This post is a description of how to setup Rtags on Emacs.  The internet is has quite a few resources about Rtags’ setup, but despite that I had to go over several of them to get things up and running for me.

Rtags is ideally meant to work for C++ projects that use CMake build systems, for others there are a few tweaks that may be needed. So here is the setup that works for developers using the traditional GNU Make for building their projects.

So here goes my setup:

To start with I had Emacs already installed, and I use Ubuntu 18.04

Installing Clang

Fire up a terminal and execute the following commands

wget -O - | sudo apt-key add -
sudo apt-add-repository "deb llvm-toolchain-xenial-3.9 main"
sudo apt-get update
sudo apt-get install clang-3.9 lldb-3.9
sudo apt-get install libclang-3.9-dev

Installing Rtags Server

Once you have clang installed now its time to install Rtags. This can be done with the following commands

git clone --recursive
cd rtags
mkdir build
cd build
cmake ..

If the make executes with out any errors then it’s time to move forward. Once this install is complete you can start the rtags server with the rdm command

rdm -j3 &

If this does not work ensure that $PATH has the path to your rtags/build/bin folder which was created in the above steps, added to it. The rdm process is located in that folder.

This will have the rdm process running and listening to build commands and create the cache for the code navigation.

Install The Rtags plugin for Emacs

Emacs being an awesome editor all you have to do is

M-x package-install RET rtags RET
M-x package-install RET flycheck-rtags RET
M-x package-install RET company-rtags RET

Now in your .emacs file add the following(sourced from here)

(defun setup-flycheck-rtags ()
  (flycheck-select-checker 'rtags)
  (setq-local flycheck-highlighting-mode nil)
  (setq-local flycheck-check-syntax-automatically nil))

;; only run this if rtags is installed
(when (require 'rtags nil :noerror)
  ;; make sure you have company-mode installed
  (require 'company)
  (define-key c-mode-base-map (kbd "M-.")
    (function rtags-find-symbol-at-point))
  (define-key c-mode-base-map (kbd "M-,")
    (function rtags-find-references-at-point))
  ;; install standard rtags keybindings. Do M-. on the symbol below to
  ;; jump to definition and see the keybindings.
  (setq rtags-autostart-diagnostics t)
  (setq rtags-completions-enabled t)
  (push 'company-rtags company-backends)
  (define-key c-mode-base-map (kbd "<C-tab>") (function company-complete))
  ;; use rtags flycheck mode -- clang warnings shown inline
  (require 'flycheck-rtags)
  ;; c-mode-common-hook is also called by c++-mode
  (add-hook 'c-mode-common-hook #'setup-flycheck-rtags))

If you use the CMake build systems the story kind of ends here, but as I said if you use the GNU Make then hold on .

A Secret Recipe for GNU Make users

Go back to the rtags folder where we synced the code from github. Remember that in step 1 we created a build folder to build rtags and that the binary rdm was present in rtags_path/build/bin

What we are going to do is use the rtags wrappers for g++/gcc to ensure that when these commands are triggered rdm process will listen and create the cache needed for it to work.

So in a terminal we will do the following

ln -s /path-to-rtags/bin/ /path-to-rtags/build/bin/g++
ln -s /path-to-rtags/bin/ /path-to-rtags/build/bin/gcc

The paths to these newly created symbolic links should already be a part of $PATH from step 1.

After doing this step open a new terminal and type:

which g++

If this returns the path to the newly created links then you are set.

Once this is done go to your project folder and build the project. If you have the terminal with rdm running you can see it is logging some information. Once this stops. You are all set. Start Emacs and open a source file. The key bindings for each action can be found on the C++ menu as shown below.


Here is a short demo of how to navigate the code using rtags


Hope you found this useful.

Thats How We C

Two and a half years back, while I was still In college that I got this idea to write a book on Programming. By then I had spent almost 4 years learning and coding a couple of programming languages. I knew I was not an expert in the field, but I also knew that I could help a few who were struggling in programming. The very next semester had a course on C programming and I knew most of my classmates would need help, so I set out on this new venture to bring out text that will help people with no background in programming to understand what C programming is all about. It can never be considered as a replacement to any of the great books out there but still, I knew that It might help someone. So after almost six months of work I was able to have a printed copy of “Thats How We C”, I sold 25 copies of the book to my classmates at no profit, I charged them with the printing cost only.
I hope many more will find this useful and if you do please do let me know, because it will be an encouragement for me to write my next book.
Also please do give me any feedback that you might have.
You can download the book from here

Classification Of Software Bugs

Who is not afraid of bugs ? Most of my readers I know will shudder just at the thought of those creepy things crawling all over you .

Just like the tag line of the Movie Eight-Legged Freaks , “Do you hate spiders? Do you REALLY hate spiders? Well they don’t like you either”

But there is another class of bugs that can ruin your sleep, your peace of mind and can really make you go nuts, we engineers call the software bugs. They can make a beautiful program a mess and can get you right back to square one. Everyone who has written a program no matter how basic it is will have encountered bugs in the first trial. Bugs can be caused due to carelessness from the part of the programmer or the programmers inability to spot out an invalid condition and it can also be caused by hardware imperfections.

No matter how much care is taken to write a bug free software is an unrealized dream and software experts claim that it will remain unrealized. Software Bugs have caused alot of trouble. Paul Bourdeaux mentions Top Ten Most Infamous Software Bugs Of All Time in his blog.

“Debugging is like removing needles from the haystack” It can be one heck of a job to find bugs in a very large program. While working on my Btech Project I encountered a Similar situation the program started giving weird results I spent almost two days checking the logic and analyzing it and the real cause of the error was a wrong argument to a function.

Despite all this There has been an effort to classify bugs in an interesting way. All those who have learned programming might have heard terms like run time errors, Logical bugs, arithmetic bugs, syntax errors etc.

But there is another classification of bugs and these are :


A BohrBug is just your average, straight-forward bug. Simple like the Bohr model of the atom: A small sphere. You push it, it moves. BohrBugs are reproducible, and hence are easily fixed once discovered. These are named after Niels Bohr, who proposed a simple and easy-to-understand atomic model in 1913. In Bohr’s model, things like the path and momentum of an electron in an atom are predictable.


A bug that disappears or alters its behavior when one attempts to probe or isolate it. No matter how much time and effort is spent trying to reproduce the problem, the bug eludes us. Such bugs were named Heisenbugs, after Werner Heisenberg, who is known for his “uncertainty principle”. According to his theory, it is not possible to accurately or certainly determine the position and velocity of an electron in an atom at a particular moment.


When the cause of the bug is too complex to understand, and the resulting bug appears chaotic, it is called a Mandelbug. These are named after Benoît Mandelbrot, who is considered the father of fractal geometry (fractals are complex, self-similar structures). A bug in an operating system that depends on scheduling is an example of a Mandelbug.


Sometimes, you look into the code, and find that it has a bug or a problem that should never have allowed it to work in the first place. When you try out the code, the bug promptly shows up, and the software fails! Though it sounds very uncommon, such bugs do occur and are known as Schroedinbugs. They are named after the scientist Erwin Schrödinger, who proposed that in quantum physics, quantum particles like atoms could exist in two or more quantum states.

By observing the problem in the code, you change the outcome — either the software works or breaks. So these kinds of bugs are known as Schroedinbugs.

Fractal Bugs

A bug, after which its resolution is found, reveals additional self-similar bugs elsewhere in the code, after which they are fixed, likewise appear elsewhere still.

Next time time you write a program and if it crashes unexpectedly you can tell your teacher or your friends that you have a heisenbug or a bohrbug in your program, let them figure out what the heck that means. Happy Hacking 🙂


[1] S.G Ganesh

[2] The Jargon File

Recursion In Programming

Recursion and recursive functions are a great concept in programming languages. For a beginner it can turn into one of the worst nightmares but once you get into the spirit of programming then writing recursive programs will be a bliss. Recently some of my friends found it difficult to write a recursive program to print the Fibonacci series upto a limit. This is what inspired me to write a small post on recursive functions. My post will be based on C programming. I am not an expert to write a large post on recursive functions but I would like to share with you some interesting things I know on recursion.

Recursion is nothing but the breaking up of a large problem into smaller problems. It is a divide and conquer policy. Here the smaller programs are defined in terms of the larger program, or we can say that a single function calls itself till a base condition is reached.

A recursion

A recursion

This picture should serve as an example as to what recursion is (How to make such a picture I will explain in some other post)

All recursive functions consist of two parts

  • A base case
  • A recursive step

It is the recursive step that is defined in terms of itself and it must move closer to the base case. If there is no base case or the recursive step does not reach the base case the program may run infinitely or till it runs out of memory. Almost all iterative programs can be done as a recursive program. Another classical example of solving a problem with recursion is the tower of Hanoi. Read more about it here

Recursive functions can make your program look more shorter and neater. But debugging and understanding a recursive program can be a difficult task. But the trick is to identify the base case and the recursive steps.

Here I will demonstrate the Fibonacci series example with and without recursion. Before you look into the program I suggest reading to really understand the fun in Fibonacci series.

The Code below shows Fibonacci series Without recursion

int main()
  int a=0,b=1,c,i,n;
  printf("Enter the number of elelments of fibonacci series needed\n");
  printf("\n %d  ",b);// to display the initial 1 of series
      printf("\n %d  ",c);
  return 0;

The Code below shows Fibonacci series with recursion

int main()
  int n,a=0,b=1;
  printf("\n Enter the number of elements of Fibonacci series to be displayed = ");
  printf("\n %d  ",b);// to display the initial 1 of series
  return 0;
int fib(int a,int b,int n)
      printf("%d  ",(a+b));
      return 0;

So much has been said about Recursive functions but any post on recursion would be misleading if I leave out the following points.

  • Recursive programs are less efficient as more memory space is used each time a function is called.
  • Iterative programs are less time-consuming and easier to write.

Despite that recursion can be fun and can really turn you on if you are a coding maniac.

A CGPA calculator for Kerala University Btech(2008 Scheme)

This C program calculate the CGPA if the GPAs of each semseter is Entered. Compile and run this program. This caclculator is based on Jerala University Btech 2008 scheme. This program was done for pure fun, I had a php version but as I formated my system lost it.

/** By Vineeth Kartha released under GPL**/
int main()
  float gpa[8],cgpa=0,intgpa=0;
  int crd12=58,crd=29,crdtot=0;;
  int sem;
  int i;
  printf("Enter number of semsters till which CGPA is to be calculated :  ");
      printf("Please Enter valid number of  semesters(1-8)");
      printf("Enter the GPA of S12:  ");
      gpa[1]=0;//since S12 mark is taken twice.
      printf("Enter the GPA of S%d:  ",i);
  printf("\n The CGPA till Semster %d is   %0.2f\n",sem,cgpa);
  return 0;
%d bloggers like this: