ALL Seated In the Boardroom?
No ! This is IT Wee are in the Server Room !
Systemini
.net
Prepared
For Millenials
One For All
All For One
Find your Domain:

Get the best name for your website

.

Characteristics of C Programming That Make It Unique (And Better)

The C programming language is the mother of all modern programming languages. Almost every language in use today includes several features which first appeared in the C language. It has been extensively used to write software for the smallest embedded microcomputers to the largest mainframes and supercomputers.

Applications written in C range in a wide variety from system software, desktop software, enterprise software, databases, etc. You would do very well to start a programming career with a knowledge of the basics of C.

A Brief History of C

The development of the C language is very closely associated with Unix. It was developed around 1972, with more additions made in later years.

Before C was developed, the Unix operating system was developed for the PDP-7 computer using its assembly language. Later a compiler for C was built on this platform, again using assembly language. At this time, C was designed to ease the development of Unix itself. Using this compiler, Unix was rewritten completely in C for the PDP-11 computer. And again, the C language compiler was rewritten in C (helped, of course, by the excellent lex and yacc tools), thus completing the C/Unix Bootstrapping process.

The main reason Unix was rewritten in C was for portability. Since assembly languages for different CPU architectures are different, porting the Unix OS to each would have been a significant effort. By developing a systems language such as C, and rewriting the Unix OS in C, this effort was reduced by several orders of magnitude.

Once the language was developed, it was recognized that it could be used to write much more than system software. And thus, C began to be used for writing software such as file servers, database servers, networking stacks, desktop software, (and later) web servers, etc.

c programming language first edition cover

In 1978, Brian Kernighan and Dennis Ritchie published the book The C Programming Language. This book served as an informal C Language Specification for many years until 1989 when C was formally standardized by ANSI. The latest version of C is C11, published in 2011.

Let us now look at some features of C that make it unique.

C vs C++: Are They Related?

As more complex software was developed in C, it was recognized that object-oriented concepts including encapsulation, polymorphism, etc would help manage the complexity. This lead to the development of C++ as a superset of C.

C++ was built by adding certain features for writing object oriented software, while maintaining compatibility with C. It was developed with the idea of progressive enhancement — making compatible changes to C language so C and C++ modules can be combined in the same program and compiled with the same compiler. This enabled older C-based modules to be re-used with minimal changes in a larger program written using object-oriented concepts.

A C program can, in theory, be compiled by a C++ compiler without requiring any changes. In practice, however, stricter type checking enforced by C++ results in errors, requiring some changes to the code.

Small Number of Keywords

The C language has been a small language in spite of its power. This is because it declares only 32 words as keywords with a specific meaning. By contrast, C++ declares 82 keywords, java has 50 reserved keywords and javascript has 63. And COBOL declares a whopping 357 keywords. Imagine the headache of having to remember and sidestep such a large number of keywords!

No Explicit String Type

Unlike most other modern languages such as Java, C++ and JavaScript, C does not provide a separate type for strings. A string is considered an array of characters terminated by a 0 character (denoted “ ”). The length of the string is denoted by a convention: the number of characters until the 0 character. You are free to ignore it and count or store past the “ ”. This lack of a proper string type and the convention has resulted in countless bugs over the years, known as buffer overflow.

In fact, the first worm to ever hit the internet, the Morris Internet Worm, was the result of such a bug in a crucial piece of system software known as the finger daemon.

Here is an example of such a bug. It illustrates how easy it is to introduce such bugs in a program. The program compiles fine, but crashes due to the buffer overflow.

# include <stdio.h>

main()
{
  char *buf = "hello world";
  buf[12] = 'a';
  printf("%sn", buf);
}

In contrast, most modern languages provide an explicit string type which make such shenanigans impossible. Even C++, which compiles the above code fine, provides an explicit std::string type.

Pointer Manipulation

A pointer is a reference to a memory location. C is completely flexible when it comes to reading and writing arbitrary memory locations. This flexibility comes at a great cost, and has been the cause of many bugs across the software spectrum. Most notable and affecting the entire internet include such bugs in web servers, mail servers and ftp servers. Even today, there are occasionally news stories about bugs caused by referencing and updating invalid memory locations.

pointers

The infamous SSL HeartBleed security bug discovered in 2014 was the result of improper management of pointer locations and illustrates the crucial importance of proper pointer management in C.

Even the occasional BSOD (“blue screen of death”) errors that are seen on Windows systems are also probably caused by improper pointer handling.

Languages other than C++ do not permit pointer manipulation and thus are not vulnerable to these class of bugs.

Arrays and Pointers Are Interchangeable

In C array references and pointers are interchangeable. The language permits usage of an array reference where a pointer is required, and vice versa. While this allows for powerful manipulation, it has also resulted in many infamous bugs.

Wide Use of “define” Macros

Macros are used to substitute a name for a different expansion. They may be used to change the definition of a name at compile time, or to substitute a longer expansion for a simple name. The C macro system supports ifdef conditionals which allow conditional compilation. This is one way software is ported to different architectures and operating systems. Generic names are defined and substituted at compile time with different expansions for different conditions.

It is also possible to include or eliminate entire sections of code from being compiled using these macros.

They are deprecated but available in C++. Other languages such as Java, JavaScript, python, etc do not provide a similar facility.

Modules Encapsulated in Files

C does not have the concept of a class, and hence does not support the notion of separate public, private and protected visibility. The only encapsulation provided by C is that of files. Functions, global variables and types defined within a source file are visible within that file only unless the names are exported. The keywords static and extern are provided for the purpose of controlling visibility of variable and function names.

By contrast, other languages such as C++, Java and Python generally support classes, and the encapsulation that goes with classes.

External Libraries

Other than basic language constructs, more complex functionality in C is delegated to external libraries. String manipulation, math, input-output, networking, etc are all provided by external libraries. In contrast, other languages usually come with a well-stocked library of modules with the language itself.

And that covers some basic characteristics of the C language, especially those that set it apart from other languages.

Have you worked with C? Did you like it or would you have preferred to work with some other language? Please explain in the comments below.



Read full article on makeuseof