DEV Community

Cover image for The C Family Tree
Tres Bien
Tres Bien

Posted on

The C Family Tree

Image by Tomasz Steifer, Gdansk from Wikimedia

Family Roll Call!

Someday, I'd love to make simple video games as a hobby. When this came up in conversation, I was informed that quite a lot of games are coded in C. I'd heard of multiple C languages and started wondering how they were related to each other.

My research began with finding which languages are actually part of the ‘C’ family. I’d assumed it was a fairly small group and that they’d all have ‘C’ as the first letter in their names, like C++ & C#. Turns out this is not the case, this family is quite large and varied!
But for now, I will be investigating just a few of the ones that matched my previous assumptions.


The Parent

Let’s start with C, the Eldest of this branch of the alphabet family. It is a general purpose programming language that was created near the start of the 1970s by Mr. Dennis M. Ritchie. Who was a computer scientist at the company formerly known as AT&T Bell Laboratories.

Mr. Ritchie created ‘C’ for the purpose of writing operating systems for microcomputers, specifically for rewriting the Unix operating system.
Unix was being rewritten because the assembly language it was originally created in had limitations that needed to be surpassed. Such as it not being portable to other architectures, so you couldn’t adapt it to work on other hardware.

While I didn’t find an Official documentation website dedicated to C,
I did learn that the C Standards Committee is in charge of maintaining the International Standard of C. You can find links on their website for purchasing updated C reference materials.
I also saw several mentioning's of this book: ‘The C Programming Language’. Which was published in 1978 and co-authored by Brian Kernighan and Dennis M. Ritchie, the language's creator. This book was considered by many to be “the authoritative reference on C” (Wikipedia).

Now for a look at some C syntax examples.
When declaring variables in C, you must first list the data TYPE before your variable name and value. So creating a variable for my pets age would be:

Int bunAge = 7;

Where “int” stands for an integer (whole number).
If I wanted to store just the first letter of his name, I would use:

char bunFirst = ‘P’;

“Char” stands for ‘character’ and is used for storing only a single character. Your 1 letter must also be between a pair of single quotes.
I'd rather keep his entire name on record in a string, but C doesn’t have a string type. So to create one, you must write:

char bunName[] = “Pippington”;

You use char with [] to create an array of single characters. Your value for this must be stored between double quotes.

Functions are declared in a similar way in that you must preface it with the name of the data type that will be returned.
Here is a function that will declare & return my pets age.

Int returnBunAge() {
Int bunAge = 7;
return bunAge
} 
Enter fullscreen mode Exit fullscreen mode

The Child

C++, also referred to as CPP or C plus plus, is a direct descendant of C. This language was ‘born’ in the early 1980s and was the brainchild of Bjarne Stroustrup, a Danish computer scientist who also worked for AT&T Bell Labs. It was originally named “C with Classes” in reference to the fact that it was an extension of C, but with the ability to create and manipulate Classes. The name was changed to C++ in 1983, using the ‘++’ increment operator to infer that it was C but ENHANCED.

As previously mentioned, C++ was started as C with the added functionality of Classes. Stroustrup’s motivation for adding classes and more to C was inspired by his research of the Simula programming language. An object oriented programming language that was designed for running a variety of simulations. However, it was too slow to be useful for Stroustrup’s needs. So he began C++ in order to beef up the much speedier C with Siumla-inspired features.

Unlike the parent, C++ has an Official website that houses documentation: isoCPP. In addition to the languages documentation, it also lists information about relevant events, the status of the language, books & other online resources that will help you learn the language.

Mr. Stroustrup is not only involved in maintaining the isoCPP website, but he also has his own site with C++ information: Stroustrup.

Now to check out some syntax examples & compare them.
Variable declaration in C++ works almost exactly the same as C’s where you must first specify the type the variable will be.
However, C++ has inherited and changed the C keyword, ‘auto’ to use with variables.
In C, auto was used when specifying the storage duration and linkage of objects and functions.
C++ uses auto to automatically deduce the type of the declared variable. Meaning that C++ knows that this is an integer:

auto bunAge = 5

C++ also has the string data type! You no longer need to combine char with an array, you can simply use:

string bunName = “Pippington”

Or auto to automatically deduce the data type as a string.

Functions are also defined & declared the same way, but C++ has added the ability of function overloading. Which refers to writing functions with the same names but different parameters.
So say I want to write a function that returns the sum of how much I spend on pet supplies. Some of the items total cost is a whole number (integer), but some involve change, and so have decimals (A ‘double’, which refers to floating point numbers).

So instead of having to give my 2 addition functions completely different names, like this:

int totalPriceInt(int a, int b) { return a + b; }
double totalPriceDouble(double a, double b) { return a + b; }

int wholeTotal = totalPriceInt(13, 9);
double floatTotal = totalPriceDouble(3.4, 8.12);

Enter fullscreen mode Exit fullscreen mode

I can give them the same name and when used they will know what to return based on inputs and the type listed in the function call:

int totalPrice(int a, int b) { return a + b; }
double totalPrice(double a, double b) { return a + b; }

Int wholeTotal = totalPrice(13, 9);
double floatTotal = totalPrice(3.4, 8.12);

Enter fullscreen mode Exit fullscreen mode

The Grandchild

C#, pronounced C-Sharp, was created in 2000 by Anders Hejlsberg, a lead architect at Microsoft, and released as an international standard in 2002. While not truly descendant of C++, C#’s design was heavily influenced by it. It’s name was repurposed from an incomplete project that was meant to be a variant of the C language. The # symbol chosen because it resembles four ‘+’, implying it to be an enhancement of C++.

C-Sharp was created for Microsoft to work with its .NET Framework. An extensive collection of libraries, frameworks, and tools for building applications for Windows, and later other platforms. They wanted a simple and clean object-oriented language that worked well with .Net and Visual Studio, which were once internal use only. However, they have since been released as free, open source resources.

Official C# documentation can be found on Microsoft's website, along with information on how to use it with .NET and Visual Studio Code. Like the isoCP site, they also keep thorough updated information and many tutorials for learning C#. they also have a Discord channel and community forums.

And now, let’s compare the syntax to its ancestors.
C# appears to create variables in the exact same manner as C++.
But instead of using ‘auto’ to automatically deduce the data type, C# uses ‘var’.

C# has Functions, but they are referred to as Methods in this language and always defined inside of Classes.


Conclusion

Each generation of this particular branch has interesting changes and improvements. It was fun trying to hunt down the similarities and differences between them. Someday I hope to have the time to research more C family members and their many branches.
As well as familiarize myself better with these languages.

Resources

Top comments (0)