Showing posts with label c compiler. Show all posts
Showing posts with label c compiler. Show all posts

Thursday, February 20, 2025

Discover the Secrets of How the C Programming Language Compiler Works, and Learn How Your Code Becomes Executable

A compiler is a software tool used to translate source code written in a programming language into executable code that can be run on a computer. This is a process that involves several stages, including lexical analysis, syntax analysis, and semantic analysis of the source code. The compiler then generates executable code that is ready to run. While simple language can be used to explain compilers, understanding their operation and translation process can be essential for software engineers and programmers who write software. That's why we separated this topic from the previous post, see here; and gave it special significance.

The first good question you would probably have for us is, in what program is the compiler for the C programming language written? If we go back a little in history, we know that older computers mostly used assembly language, while higher-level programming languages began to develop when the benefits of reusing software on different processors increased. The first higher-level programming language, Plankalkül, was proposed as early as 1943. Since then, several experimental compilers have been developed. Fortran's team, led by John Backus of IBM, introduced the first complete compiler in 1957. Since then, compilers have become increasingly complex as computer architectures have evolved.

Today, it is common practice to implement compilers in the same language that is being compiled. Therefore, it is assumed that the compiler of the C programming language is coded in the C programming language, as for example all .Net programming languages have an open-source Microsoft compiler called Roslyn which is written in the C# programming language. However, to create the first C compiler, its creator Dennis Ritchie used the previous programming language B, which was developed by Ken Thompson.

Compiling files written in the C programming language is not uncommon even in the most modern corporations

Compiling files written in the C programming language is not uncommon even in the most modern corporations

Dennis Ritchie later expanded the B programming language and created the C programming language, so the original C compiler was also written in B. We mostly use GCC compiler version 14 or newer, this text was written in 2025; and there is no theoretical chance that you will find any command in the B programming language in it. Because the GCC compiler does not support the B programming language, it considers it too obsolete. But we know that the GCC compiler is written in a combination of the C and C++ programming languages, with the possibility that it may also contain some parts written in other programming languages such as Objective-C and some newer ones.

When you flawlessly write C code in any text editor and create a text file, you can call the C compiler to translate it into machine code so that your program can run. The compiler runs a translator or translation unit, known as a Translation Unit, which consists of the source file and header files that are referenced using #include directives. If your code is correct, the translator creates an Object File, which we recognize by the. o or .obj suffix, and we call such object files modules. The standard library of the C programming language contains translated object files in machine language, which allows faster access to standard functions that we call in our programs.

It is important to note that when we say that a file is translated into machine language in the C programming language, it is first translated into assembly programming language in a temporary file, which is then translated into machine language, after which the temporary file is deleted. When compiling a program, we recognize such a file by the . s suffix. The translator separately translates each source file with all the header files it contains into separate object files, i.e., modules. The translator then calls the Linker, which combines all object files and all used functions from the library into an Executable File. Do not confuse this process with .Net technology. In .Net technology and the C# programming language, things are different.

How the C Programming Language 'Understands' Your Code: A Journey Through the Compilation Stages

Monday, February 17, 2025

Learn C Programming Language, A Practical Guide

Although C programming language is no longer as dominant as it once was, it still has its strong application in systems programming, embedded systems, operating systems, and performance-critical applications. The Python programming language has taken over the lead in education due to its simplicity, but C remains irreplaceable in areas where direct control over hardware is needed. Known for its efficiency and flexibility, C is the foundation of many modern programming languages, including C++, Java, and Python. Whether you are a beginner who wants to start with programming or an experienced programmer who wants to deepen your understanding of low-level computing, learning the C language is an excellent choice. This C tutorial and practical guide will help you understand the basics of C programming, covering everything from setting up a development environment to writing and compiling C programs.

The C programming language is a general-purpose procedural language. It is not at all difficult as it is said, because it is only a set of correctly written instructions that the computer will execute. It was created in Bell Laboratories in New Jersey. Its creator, Dennis Ritchie, originally designed and implemented it for the UNIX operating system on a DEC PDP-11 computer, with the aim of replacing assembly language in solving systems programming. Despite the fact that it is generally rarely used today, its extension and successor is the C++ programming language, because unlike the C programming language, it supports object-oriented programming. However, before you step into the C++ programming language, we think you should first learn the C programming language. It is fully accepted by the C++ programming language, so it will also be much easier for you to learn and program in C++ afterwards.

The C programming language is often taught through Linux, especially at universities and technical school

The C programming language is often taught through Linux, especially at universities and technical school

Today, the C programming language is often taught through the Linux operating system more than through Windows or other operating systems, especially in universities and technical schools. The reasons for this are:
  • Natural environment for C – The Linux kernel is written in C, which makes it ideal for learning systems programming.
  • GCC and open-source tools – The GCC compiler and tools like gdb, make, and valgrind are standard in the Linux environment.
  • Terminal-based approach – Linux encourages working through the command line, which allows for a better understanding of compiling, linking, and running programs.
  • Learning programming while working with system resources – Students often learn how to manage memory, processes, and files in a Linux environment.
However, in a corporate environment, Windows is still used for C programming, especially in combination with the Microsoft Visual Studio environment.

How to Set Up a Development Environment for C Programming?