ENTERING INTO THE WORLD OF C PROGRAMMING LANGUAGE
My first exposure with the C programming language was yesterday, but JavaScript was the first computer language I ever learned. Although I haven't used JavaScript in approximately three months.
My current online school gave me assignments on the Preprocessor, Compiler, Assembly, and Linking phases of the C compilation process as my initial introduction to the language. These phases deal with converting code that is easy for humans to understand into machine code that the computer can quickly execute.
It is almost like using a translator when you want to communicate with someone who speaks a language other than your own. In order to the best of my ability and comprehension, I will describe these compilation phases in C.
PREPROCESSING
This is the initial stage of compilation in C programming; it removes comments and expands macros after checking the libraries, which are indicated by the #include, in the code. The stdio.h and the unistd.h are two examples of C libraries. Every time one of these libraries is used, it must be declared because each one has its own functions. The "#include stdio.h>" library is necessary for the printf function to function.
To have access to the Processor file using gcc you only need to type this code:
gcc -E filename.c > filename
The preprocessor output of the file filename.c is saved in a new file filename as a result of this command.
COMPILING
The compiling stage follows, which simply transforms the code to assembly code. It serves as an intermediate between preprocessing and assembly. At this point, the code is still written in English.
To have a look at the code in the compiling stage, you use need to run this:
gcc -c filename.c
The output of running this command would give a file with a .o extension i.e. filename.o
ASSEMBLY
The third stage of compilation is where the code is no longer in English or another human-readable language and has already been converted to binary or machine code, which a computer can readily understand.
To have a look at the assembly code, then you should run this command:
gcc -S filename.c
Following the execution of this command, a new file with the .s extension would be created, containing the assembly code.
Note: Every file used to program in C always have the file named with .c as the extension.\
LINKING
Really, all I have to say about this procedure is that it is the final step in the compilation process and converts all the codes into executable files.
PRINTING HELLO WORLD! ON C
I would create a straightforward C program that outputs Hello World in this section of the article. additionally generates every piece of code that goes through the compilation process, i.e. I would execute only the preprocessing commands listed above.
I am using a Linux Ubuntu20.04 to run my commands and to create files, I am using the vi editor.
Hello World! C programming code
How to print "Hello World" is shown above. in C programming. As was previously mentioned, a library called "#includestdio.h>" must be used when using a function inside the library. My comment for the code, which is redundant and always removed during compilation, is found from my second to fifth lines. The code is formatted as follows:
#include
/**
* main - Printing Hello world!
* Return: Always 0 (Success)
*/
int main(void)
{
printf("Hello World!\n);
return(0);
}
Printing Hello World! using Basic Compilation
The gcc filename.c command is used to execute basic compilation. It is important to note that when I created my file, I used the.c extension, resulting in the filename: "hello.c."
When you run the basic compilation command, you will get a new file named a.out that contains the compiled output. To use it, simply type ./a.out, as shown in the screenshot below.
After running the command, you get your Hello World! output.
To Print the Preprocessing Output
To print the preprocessing output, simply execute gcc -E filename.c > filename. This command redirects the output to the new name "filename."
So, if I want to use this command on the hello.c file, it can be gcc -E hello.c > hello, or we can give it a another name entirely, gcc -E hello.c > testing. All provide the same output, but are saved under distinct file names.
The image above shows that after running the program, a file named testing was saved, including the output after preprocessing. After running the code, the preprocessing code is shown below.
This is what the code looks like after passing the preprocessor stage.
To print the compiling and assembly output, you only need to follow the gcc commands given above.
While attempting to study and share them in order to reinforce my learning, I will do my best to share my journey into the world of C Language. I'm hoping you will be with me on this adventure.
WHO IS STARSTRINGS01
Designed by @ grisvisa
Starstrings01 AKA Giftedhands is a Hive lover, a Nigeria musician (Guitarist), and also a student who studies Mechatronics Engineering at the Federal University of Agriculture, Abeokuta.
His goal on Hive is to be more than a regular blogger but something more; someone with a purpose. That’s one of the reasons why he founded the newbies initiative @newbies-hive to help guide and support newbies. Kindly click here to follow the
@newbies-hive curation trail.
He battles and struggles with balancing education and being active on the chain but yet his love and passion for Hive keep him on balance.
All images are mine except indicated otherwise
IF YOU LOVE THIS POST, YOU CAN KINDLY SUPPORT IT WITH YOUR COMMENTS, REBLOG AND UPVOTE. IT WOULD BE MUCH APPRECIATED
THANKS FOR VISITING MY BLOG 😇💕
Leave ENTERING INTO THE WORLD OF C PROGRAMMING LANGUAGE to:
Read more #programming posts
Best Posts From GIFTED
We have not curated any of starstrings01's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From GIFTED
- ACCOUNT RECOVERY PROCESS NOT GOING THROUGH!!!
- Spiritual Laws of Progression: The Power of Vision || PART 2
- Spiritual Laws of Progression: Lessons That Transformed Me
- Seeing Beyond the Situation: Embracing Vision and the Power of Dreams
- How Badly Do You Want It? | How Desire and Action Create Change
- Little Drops, Mighty Oceans: Why Small Steps Matter More Than You Think
- Living with Intention: Crafting Your Personal Mission Statement
- Should Social Media Be Taught in Schools? The Hidden Opportunities & Dangers for Youth
- The Price of Ambition: Embrace Sacrifice to Achieve Your Dreams
- Buy Now or Pay More Later: Lessons in Financial Literacy