I was writing a few simple C programs with an engineering student, in the process, we were making a lot of small changes to observe how the program behaved.

For example,

  • adding or modifying the print statements here and there
  • removing certain condition or comment out a block of code to see how it behaved
  • sometimes making mistakes and program wouldn’t compile

Simple C program execution is

Occassionally I would forget to re-compile before executing ./a.out. So I started doing,

Now this improved two things,

  • No need to type 2 commands
  • Never forgetting to compile and later noticing “ah! I missed to compile before executing”

Then I thought, this too is combersome, instead I should have a tool that could “re-compile” and “execute” everytime. After all these are lab programs, they hardly have any noticeable compilation time.

So my desired command would be,

This run should support two things,

  • compiler arguments; such as -lm for programs involving math.h
  • cli arg inputs for the executable; example case is, ./a.out myarg1 myarg2

If these two are supported, then pretty much all engineering lab programs would work with the run tool.

This run tool can be a shell script,

Alright, now the script is ready, all I have to do is, ensure it is on the path thus accessible from anywhere in my laptop.

Test it, write a simple hello world program hello.c

In case there is a mistake in compilation, it simply shows the output directly from gcc command execution,

I believe it is important to have these kind of re-usable toolings for one self – so that the focus can be on what really matters.

In this case atleast, we were trying to implement concurrency concepts by program, wanted to focus on the code design, logic, thinking about the control flow (not fighting with gcc commands).

Leave a Reply

Your email address will not be published. Required fields are marked *