Waivio

Recommended Posts

ENTERING INTO THE WORLD OF C PROGRAMMING LANGUAGE

32 comments

starstrings0114.4 K2 years agoPeakD6 min read

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.

https://files.peakd.com/file/peakd-hive/starstrings01/23vhq7Shbh22C8ew2SDPTADwT71RjBD8kn5CKmqRpCDmfhvv5Vh7nGqy9dsUaun8TvykB.png

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

https://files.peakd.com/file/peakd-hive/starstrings01/23tGPTo554UdVWCAoNHvL8v2W74FwUmPaQci88Qy1xn2DW9EcWrvubWE3xKedxYdNHZPe.png

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<stdio.h>
/**
 * main - Printing Hello world!
 * Return: Always 0 (Success)
 */
int main(void)
{
    printf("Hello World!\n);
    return(0);
}

Printing Hello World! using Basic Compilation

https://files.peakd.com/file/peakd-hive/starstrings01/23tGRKmdSwtYnUP9A7VsS1AnAeiEtVeapttPNgmboEY6dX4FyTWqymQPoZBNAbQ5MKaKk.png

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.

https://files.peakd.com/file/peakd-hive/starstrings01/23tGVvEqomuofG9GegGDhuK9x1yQcMfkj27bxZxV7DhrLV6rcXcx7cQraFwLXAicFqbBn.png

After running the command, you get your Hello World! output.

https://files.peakd.com/file/peakd-hive/starstrings01/Eo44kfcWSvF2t47HcxmsFLrPeJtaWKmTn2M3ujPQbn7QyMoUA8dMPpaWEcDy7HMp8Fa.png

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.

https://files.peakd.com/file/peakd-hive/starstrings01/23tGVQt8JW59fnKdBQUngRi4C8LwaQGRSyNDQ1CnH1THpph4RPkvsczAZvprknnaW9gFZ.png

https://files.peakd.com/file/peakd-hive/starstrings01/23tGTdosQ9CWq1o1Ko9WsrToaBBjrpz8hhxBuX33pVaUdVadXFu79RjrjT79VrsT3e21T.png

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.

https://files.peakd.com/file/peakd-hive/starstrings01/23swcK94qy9WMfSEA4PpEzZj3ot3MwazNjwEhyqzEDFQQWYA2K1zv9Vr2wXFWRJTh1Nrd.png

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


https://files.peakd.com/file/peakd-hive/starstrings01/AK7xcxJMNXNSsRMjNThqUGyM4TUZESzubTPprqMxAV6bQgq3jhAWWSYqfEhPe7M.png
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


https://files.peakd.com/file/peakd-hive/starstrings01/nvnkde2T-54TLbcUcnRm3sWQK3AJf6fuxkTxiKXRNCarffscTjF9JnBqLzj89NH5s1rKH2Cga4QvMPvvEcb4koTvuCHZXnviw8k7xAcqd9HsbFKjw6hj1Y72M87h86FHy9hno4Dmynf1K26XEe.png

IF YOU LOVE THIS POST, YOU CAN KINDLY SUPPORT IT WITH YOUR COMMENTS, REBLOG AND UPVOTE. IT WOULD BE MUCH APPRECIATED

https://files.peakd.com/file/peakd-hive/starstrings01/nvnkde2T-54TLbcUcnRm3sWQK3AJf6fuxkTxiKXRNCarffscTjF9JnBqLzj89NH5s1rKH2Cga4QvMPvvEcb4koTvuCHZXnviw8k7xAcqd9HsbFKjw6hj1Y72M87h86FHy9hno4Dmynf1K26XEe.png

THANKS FOR VISITING MY BLOG 😇💕

Comments

Sort byBest
AI
Waivio AI Assistant
How can I help you today?