What C is…
A Brief History
C is a computer programming language written in the 1970’s by Dennis Ritchie. It is a functional language, as opposed to more modern object-oriented languages like C++ or higher-level languages like Java or C#. At its most basic level, it could be thought of as a reasonable alternative (in most cases) to programming in Assembly, which can be quite different across each platform.
What is C Used For?
There are dozens or even hundreds of C compilers out in existence. C in almost all cases is always compiled to native code for whatever platform is being targeted. However, it can also be compiled to “byte code” (see Emscripten) and targeted to WebAssembly (so your application could run in any browser).
C is an extremely flexible, performant (limited only by the efficiency of the compiler) and supported language. Even though C is not a “write once run anywhere” language like Java has been sold to be, it really is one of the first examples of “write once run anywhere” as it provides a way to write code that is not processor specific (the compilers will convert it to the appropriate platform).
Most all of compilers or virtual machines that are used for languages today (Python, .NET, PHP and most others) are written in C (or C++, which is really just a set of supported “extensions” on top of C to make it more objected-oriented). Game engines, common libraries and things that require performance, are all additional examples of things that are written in C.
What C is NOT…
C is not considered a high-level language (although it used to be). It does not offer many of the typical things that we see in modern languages. C does not have…
- Memory management (reference counting or garbage collection) - You have to allocate/deallocate any memory you allocate. This makes it extremely prone to memory leaks, although there are tools today that make these much easier to find than they used to be (see LeakSanitizer link below).
- Built-in support high-level constructs like Dictionaries, Sets, Lists, etc. - Although there are a multitude of third-party libraries that add support for these types of things.
- No need for pointers - In C, eventually you will have to use and understand how “pointers” work. A pointer is a value (32-bit or 64-bit typically) that represents an address (or reference) to somewhere else a variable is stored. Most high-level languages hide this part from the developer, but in C, you work with pointers regularly.
Where Should I use C in 2023?
While Java is touted as a “write once, run anywhere” language, C is really where it’s at. In particular, for libraries or common components that you want to be language (called by any language) and platform (runs on anything) agnostic, C is really the right choice for the job.
One of the big problems with C historically has been to write C and Makefiles (similar to project files) that work across multiple OSes and hardware. More recently, CMake has been the option of choice for most projects. CMake aids tremendously in creating project files that then get converted to a Makefile on-the-fly for a given platform. This goes a long way in allowing developers to not spend so much time and resources getting their projects to compile and link on many platforms. A proper CMake file can basically “just work” on whatever platforms that CMake supports.
Outside of straight up ASM code, you cannot beat the performance of C. Even C++ can add enough overhead that justifies not using it over C. For tiny/inexpensive embedded systems, there can be so many resource constraints, that C could be the only reasonable option to use.
Games are another big factor. Many modern games are 3D intensive and often push hardware to its limits. Many game engines, while heavily developed using scripting languages, are written in C.
When speed and memory usage of your code is a high priority, there is no better option than C.
C is a great way to learn coding. In fact, my recommendation to most new developers is that they learn C as their first language, or very early on in their education. Not because it is the easiest language, but C is really, what I like to call, a “lowest common denominator” language. If you are familiar with C and how memory allocation and pointers work, you can learn anything else. C can give the most insight into how applications, compilers and operating systems work.
The C Programming Language (a good history lesson) - https://en.wikipedia.org/wiki/C_(programming_language)
Emscripten - https://en.wikipedia.org/wiki/Emscripten
WebAssembly - https://en.wikipedia.org/wiki/WebAssembly
CMake - https://cmake.org
CLang/LLVM - https://clang.llvm.org
LeakSanitizer - https://clang.llvm.org/docs/LeakSanitizer.html
The JBS Quick Launch Lab
Free Qualified Assessment
Quantify what it will take to implement your next big idea!
Our assessment session will deliver tangible timelines, costs, high-level requirements, and recommend architectures that will work best. Let JBS prove to you and your team why over 24 years of experience matters.