Back in 2012, after my article on Linux ELF Virus was published in Linux Journal, I was curious to come up with a trigger point for this virus. I mean what would compel a Linux user to execute it for the very first time? I thought about it many times but could not come up with something in a working state.
Cut to the present times – Last Friday, when I was coming back from my office through office bus, I was indulged in some technical talk with a guy who works on encoders and decoders for various media file formats. Suddenly the same thought struck in my mind and I asked him whether it is possible for him to come up with a situation where a Linux user clicks on an image file, the image gets displayed but a notorious code gets executed in the back end?
The most compelling feature of C++ programming language is it being object oriented. An object is a fundamental aspect of an object oriented language like C++. The objects come from classes which is a collection of related type of information. As in C, we have structures as a user defined data-type, which is a collection of data members of different data-types. On Similar lines, C++ introduces the concept of classes, though with a lot of basic differences like the concept of constructors and destructors etc.
Let’s discuss a few differences here :
- C structures just have data members, whereas C++ classes, apart from data members, can also have member functions.
- C structure data members are all publicly accessible, however C++ classes have the power to specify access as private, public or even protected.
- Another vital difference are constructors and destructors. To initialize objects, including dynamic memory allocation, implicitly in C++, programmers define constructors, and similarly, to destroy an object, including freeing the memory, it uses destructors. In this article, the we shall have an in-depth understanding of the C++ constructors and destructors.
[Note that, in the explanation above, we have discussed about C structures... C structures carry a lot of differences with C++ structures.]
In this article, we will discuss in detail the intricacies of constructors and destructors from a developer’s point of view.
It is said, that the biggest and toughest problem can be solved by breaking it down into smaller problems and then solving it. One of the technique based on similar lines is recursion. Recursion in simpler and theoretical terms is solving a problem by solving smaller problems of “same” form and using their results to compute the final result. We will delve into the mathematical and programmatic understandings, but prior to that, lets understand the abstract concept of recursion through an example.
Suppose there a volcano at a place in country A, which erupts in a set pattern which has been observed. That is, it has been observed that it erupts after twice the number of years of its previous eruption. As in, if last volcanic eruption was after 1024 years, then the next eruption will be after 2* 1024 = 2048 years. Now, we want to compute how many years have passed since the volcano is active?
While designing a simple C program or a full fledged command line application, it is pretty usual to have a requirement for arguments to be passed while running the executable/application. These arguments are known as command line arguments. These parameters govern the behaviour of the program to some extent, as these are the inputs based on which output is computed/displayed.
Another usage of these command line arguments comes in the form of various options of a command, be it on Linux, Windows or any platform. In Linux, any command is actually an executable being triggered through Linux shell. In code, the entry point to this executable (in ELF format) will be the main() method . The Linux shell communicates the command line arguments to the program by passing these parameters to the main() method. In this article, we shall go through the advanced concepts related to command line arguments in Linux using C programming examples.
Most of the C projects are not single file projects. The code is spread over tens or hundreds of files. Now suppose there is a situation where you have declared and defined a variable in one file (say file1) and want to use the same variable in other file (say file2) by just telling the compiler that this variable is already defined somewhere else. What would you do? Well, this can be done through the concept of extern variables in c.
If you have worked on Linux software development using C language, you would have definitely come across the gcc compiler. It is one of the most popular C compiler as of today. GCC contains a huge list of compiler options. For those who are new to gcc, they must have knowledge of some basic gcc compiler options. This article would discuss five gcc compiler options that I personally use the most.
The other day I was reading a survey on programming languages and I found that as of today, C programming language is still in the top 3 most used programming language by developers across the globe. With so much code being written in C, I thought to share some of the good C programming practices that I have learned over the years.
If you are new to C programming and use the library function gets() in your programs then its time that you stop and switch over to other alternatives. This is because the gets() function is not at all a safe function to use. Here in this article we will discuss buffer overflow in C using gets().
While writing C code for Linux programs, it’s very important to put in place proper error handling mechanism as it saves precious time while debugging any problem with the same code. Mostly developers write code that contains broken error handling and this causes them to invest hours while debugging a complex code. In this example we will discuss in detail how to perform error handling in C.