<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; Ritik Sharma</title>
	<atom:link href="https://www.emblogic.com/blog/author/ritik004sh/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>what is the compilation process in c program.</title>
		<link>https://www.emblogic.com/blog/03/what-is-the-compilation-process-in-c-program/</link>
		<comments>https://www.emblogic.com/blog/03/what-is-the-compilation-process-in-c-program/#comments</comments>
		<pubDate>Tue, 03 Mar 2020 12:24:50 +0000</pubDate>
		<dc:creator><![CDATA[Ritik Sharma]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=20933</guid>
		<description><![CDATA[Compilation process in C program There are four phases for a c program to be execute, 1.pre-processor 2.compiler 3.assembler 4.linker let’s start with the first one, #Pre-Processor- The pre-processor removes the comments and include header files in source code, replace &#8230; <a href="https://www.emblogic.com/blog/03/what-is-the-compilation-process-in-c-program/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="margin-bottom: 0in;line-height: 100%"><span style="text-decoration: underline"> <span style="font-size: xx-large"><i><b>Compilation process in C program </b></i></span></span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large">There are four phases for a c program to be execute,</span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large">1.pre-processor</span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large">2.compiler</span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large">3.assembler</span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large">4.linker</span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large">let’s start with the first one, </span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><i><b>#P</b></i></span><span style="font-size: large"><i><b>re-</b></i></span><span style="font-size: large"><i><b>P</b></i></span><span style="font-size: large"><i><b>rocessor-</b></i></span> The pre-processor removes the comments and include header files in source code, replace macro name with code.</span></p>
<p style="margin-bottom: 0in;font-style: normal;font-weight: normal;line-height: 100%;text-decoration: none"><span style="font-size: large">Basically, it is a program that processes its input data to produce output that can be used by another program as its input. Obviously, compiler is the next one,</span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><i><b>#Compiler- </b></i><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">A compiler is a program that processes your written data which is in your language convert into machine language i.e. </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">binary form(0 &amp;</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">1).</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">B</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">asically, it generates the assembly code of the file, it converts the (.i) file into the (.s) file. </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">Any file entering into compiler program </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">passes through lexical analysis, syntax analysis, intermediate code generation, code optimization, </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">object code generation. </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">And the next one is,</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><i><b>#Assembler- </b></i><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">An assembler is a program that converts assembly language </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">or assembly code</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal"> into machine code </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">or object code</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">. Assemblers are similar to compilers in that they produce executable code</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">s</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">. </span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">I</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">t converts the (.s) file into the (.o) file. Finally, the last one is,</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><i><b>#Linker- </b></i><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">A linker is a computer program that takes one or more object files generated by a compiler and combines them into one, executable program.</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">There are two types of linker i.e. static linking and dynamic linking.</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%"><span style="text-decoration: underline"> <span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">Static linking</span></span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">is the result of the linker copying all library routines used in the program into the executable image. </span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%"><span style="font-size: large"><span style="font-style: normal"><span style="text-decoration: underline"><span style="font-weight: normal">Dynamic linking </span></span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal"> is done during load or run-time and not when the exe is created. </span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">I</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">t converts the (.o) file into the executable file for example (.elf) file.</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">Now let’s create a simple program,</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">First we write our program in the vim editor* *(you can use any editor)</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">#include&lt;stdio.h&gt;</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">int main()</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">{</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">printf(“Hello, This is Ritik Sharma\n”);</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">return 0;</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">}</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">save the file with a name and (.c) extension </span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">and then exit from the vim editor</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">now compile the file with the compiler for example gcc,</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">then execute the file which is ./a.out and you can see the output as given below,</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">Hello, This is Ritik Sharma</span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">nice! You got the output. If any error occurred during compiling the program then note that error and try to correct th</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">at</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal"> error. </span></span></span></span></p>
<p style="margin-bottom: 0in;line-height: 100%;text-decoration: none"><span style="font-size: large"><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">_</span></span></span><span style="font-size: large"><span style="font-style: normal"><span style="font-weight: normal">THANK YOU_</span></span></span></span></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/what-is-the-compilation-process-in-c-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
