An introduction

Every programming language has a technique, syntax, a compiler, a linker and an operating system of its own. It is necessary to know all these elements well before proceeding with programming using the language. It is also necessary to know how other languages behave and perform given the same parameters. Basic is interpreted i.e. each line is sequentially interpreted by the OS at run-time; C & C++ are compiled and linked to executable code, which the compiler understands, and subsequently executed. But C & C++ are different when it comes to paradigm; C is a procedural language whereas C++ is an object-oriented language. Before I embark on a lengthy explanation on techniques and stuff, it becomes imperative to know what is "procedural" and what is "Object-oriented".

As I said in the beginning, each language has a technique all its own. So that is this technique? In simple, layman terms, a programming technique can be defined as, the ways or means adopted to solve a problem, programmatically. Although both C & C++ are function oriented, the paradigm behind the definition or these functions differs highly. A function is called a 'method' in C++ and 'function' in C. For the uninitiated, a function is a set of program statements and a program is a set of functions. In both the languages, functions are called from the "main" function and these functions return values to the calling functions. But what is this "main" function or for that matter, what are these functions ? As I said, a function is a set of program statements but, so is a program. So, where does the difference set in ? Let us see.

When you write a program you actually issue a set of instructions to the computer in the form of syntactically correct statements, which can be simple arithmetic expressions or can be commands in the form of calls to pre-defined functions. Again we meet this dreaded word – "function" and we can safely understand, due to its constant appearance & re-appearance, that a function must be an integral and the most important aspect of a program. Every program has a collection of functions but only one 'main' function. The "main" function as the name suggests, is the main function and is executed first, as soon as the program is loaded into memory and all other functions are called from it.

Of course, a function can also be called from other functions and need not be called from the "main" function. Here, the similarity between C & C++ ends. Because where, in C, you can just write trillions of functions, one after the other and let them loosely lay around, in C++, all the functions in the program need to belong to "a class". Period. For the moment. A program when it is written by you is saved onto a file. You can understand the file as a container for your program. A program has a paradigm, as has been noted thus far, and OOPS in this paradigm which demands that you, as a programmer, must place or declare your functions to be members of a class. How do you achieve this? When the terms "definition", "declaration", "expressions", "paradigm" etc. are used in the context of programming, all it means is that, you need to adopt or conform to the syntax which is the grammar of the language, when writing your program.

Syntax

Syntax is the basis on which you write your computer program. As there is grammar for English, there is syntax for every computer language. The compiler which checks or, in technical terms, compiles your source code into a .obj file, it checks for any errors that may have been committed by you. These errors can be logical, syntactical, linker or run-time errors. Syntactical errors are those errors which occur due to spelling or typographical (typo errors as they are popularly called) errors. Logical errors are those errors which are caused due to illogical loops, conditions or blocks of code. Linker errors are those errors which are generated by the linker e.g. a ‘typo’ error in a call to a pre-defined function – set_fillstyle is a graphic function but if you misspell it as set_filstyle, there will be a linker error. Run-time errors are those errors which are usually caused due to the inability of the underlying platform or operating system to carry out an instruction, command issued by your program.

Technique

In the beginning I talked of technique. Technique is the style or methodology employed by the programmer to automate a manual process. In C, there is not much of technique involved. In C++, there is technique and technique only, because C++ works on the OOPS paradigm which has its own set of rules and techniques. So, technique is related to paradigm and if the paradigm is OOPS, then the technique is also OOPS.

OOPS is a methodology employed to convert manual, real-life problems into computer programs. OOPS has some salient and typical features which are drastically different from other methodologies like structured, procedural and any other type of language. The root of OOPS can be traced down (according to popular opinions) to an university in the United Kingdom which had 3 types of living beings to tackle when maintaining inventory of livestock in the campus. When this problem was to be automated, the programmers found that they could work much better when dividing the livestock into respective classes i.e. human livestock was maintained under the human class; animals under the animal class and so on. Characteristics of a human being could be classified as attributes; and objects could be made to represent other properties typical of the class. And slowly a gem of a methodology formed which gave birth to terms like "abstraction", "inheritance", "polymorphism", "objects", "prototypes", "members of a class", "instances" etc. and these terms have become almost synonyms for superior and sophisticated doctrine of programming.

Rules became, which stated that members of a class would be given total security - in the sense, that only members of the same class could access other members of the class. For instance, in real life, if you were to join a club, only after you join the club by paying the fees and filling up the form would your status change to that of a member and only after your status becomes that of a member are you allowed to access the benefits of the club plus talk and make friends with other members of the club. Similarly, to access the features or attributes of a class, an object of type class needs to be defined or created and only then the attributes, members and other features provided by the class will be open for access ! This is called data-abstraction in OOPS. More and more concepts came into being, which were added and soon, C++ became a robust, object oriented language, which due to the newest principles and rules soon came to be known as a "blue-eyed language". At the same time, "smalltalk" was also gaining popularity as a OOPS language.

I shall discuss, in as full a detail as possible, this wonderful technique which was widely used, till recently, as a programming language to develop Windows programs ! This was primarily due to the fact that since C++ is an object-oriented language and Windows is an object based operating system, C++ was considered a sufficient language to develop Windows applications.

Operating system

So, what is this operating system ? An operating system is the platform on which all computer programs run. As a computer language has a syntax of its own so do operating systems. Communication between the computer and the programmer is through the English language. Communication between the computer program and the operating system is through a language called the binary or the computer language which is a combination of "o’s" & "1’s". Let us quickly understand the communication part. When you write a C or C++ program, the instructions provided by the programmer is in the form of commands or instructions, within the framework of the syntax of the language, which is usually in the form of English verbs or statements. But the computer does not understand English ! So, how does your program work ?

Your program, written in C or C++, is converted into an object code by a C or C++ compiler which is further linked onto an executable form. There are three new terms in the above statement. 1. object code 2. compiler & 3. executable. Let me briefly define these terms. Object code has got nothing to do with OOPS. It is so named because it is an object for the linker. The compiler is a software i.e. a computer program which converts your English statements and commands into an object code, which the linker can understand and further on, the linker will convert this object code into an executable form (the final binary form) which the computer will understand.

You must have heard of the DOS operating system as well as the Windows operating system. DOS operating system is a text-mode operating system. A text-mode operating system is different from a graphic mode operating system, which Windows is. That is, Windows can provide and support a rich set of visually pleasing screens and even movies because of its mode while DOS cannot, again because of the mode. What is this mode ? Mode is the operating schema of some device of the operating system, in this case, the display device. The display in text-mode i.e. DOS is enabled by a matrix of 8x8 characters while the graphic mode i.e. Windows, is enabled by a collection of picture elements or pixels as they are popularly called. C & C++ are primarily text-mode programming languages but they can also provide graphic functionality to your program through a special graphics driver that will run the graphics mode upon the text-mode ! A graphics driver is a software which will support or initialize the graphics card in your computer so that your program can support graphics and graphic functions.

C & C++ are powerful programming languages, which are, even today, highly popular despite their many limitations and to such an extent that, a new language has just entered the programming world called C#, a language for the internet, which is heavily based on C++. They are powerful languages because they provide lowest possible interaction with the operating system at the easiest level.

So let us explore this wonderful world of the two C’s and see if the two C’s are easy or not !!

 

 

 

Written by

J.V.Ravichandran