<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Diego Jeanluck Linares Castillo on Medium]]></title>
        <description><![CDATA[Stories by Diego Jeanluck Linares Castillo on Medium]]></description>
        <link>https://medium.com/@wardencode?source=rss-cd7d608392b7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LgXOUWfz2GEpW42d2DxYcA.jpeg</url>
            <title>Stories by Diego Jeanluck Linares Castillo on Medium</title>
            <link>https://medium.com/@wardencode?source=rss-cd7d608392b7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:48:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wardencode/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Recursion]]></title>
            <link>https://wardencode.medium.com/understanding-recursion-4d1d57260eb1?source=rss-cd7d608392b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d1d57260eb1</guid>
            <category><![CDATA[recursion-in-c]]></category>
            <category><![CDATA[c-language]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Diego Jeanluck Linares Castillo]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 07:19:09 GMT</pubDate>
            <atom:updated>2022-07-04T07:19:09.440Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0gAgLbmKlyI40QPV.jpg" /></figure><p>Recursion is the way that how is specified a <strong>process based on its own definition.</strong><br>But in <strong>programming terms is equal to using a recursive function</strong>. <strong>But…</strong></p><h4>What is a recursive function?</h4><p>A function is recursive when it&#39;s called by itself inside of its own definition, either directly or indirectly (through other functions).</p><h4>Some popular examples of problems recursive in nature:</h4><ul><li>Fibonacci</li><li>Factorial of a number</li><li>Go through graphs</li></ul><h3>Advantages and disadvantages of recursion:</h3><p>Recursion like any other concept has advantages and disadvantages, we are going to see some of them know “why” and “when” to use recursion.</p><h4>Advantages:</h4><ul><li>In most cases, recursion uses few lines of code, making the code “elegant” to the eye.</li><li>It&#39;s useful to explain and execute problems of recursive in nature (be efficient).</li><li>Usually is more simple to apply than that an iterative solution.</li><li>It’s useful to know the recursivity because we can use it to design algorithms.</li></ul><h4>Disadvantages:</h4><ul><li>High use of memory.</li><li>Isn’t efficient in most cases.</li><li>In some cases, it’s hard to understand (hardly to explain or that someone understands the code easily).</li></ul><h3>Example of a recursive function (_pow_recursion)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*bUaSeNRwd81kFZ4Z5NH6Gg.png" /></figure><p>This function <strong>finds the result of x to the power of y </strong>with recursion<strong>.</strong></p><p>This function allows the positive, negative, and floating numbers.</p><h3>Parts of a recursive function</h3><p>A recursive function has 3 important parts:</p><ul><li>Base Case</li><li>Call itself (directly or indirectly)</li><li>Code</li></ul><h4>Base Case</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*htXHQ0zgN1F_0TGGo6sW-w.png" /></figure><p>Well the recursion is a kind of loop and like any other loop we have to break the loop and we do this with the Base Case.</p><p>A default case that always will be reached, because the other way we’ll get an infinite loop.</p><h4>Call itself</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2R_Biy6qds0IZRn6_9Wdg.png" /></figure><p>To make able the recursion we must call the function inside itself like this.<br>We have two different calls to the function.</p><p>One is for when the exponent is positive and the other is when the exponent is negative.</p><h4>Code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*bUaSeNRwd81kFZ4Z5NH6Gg.png" /></figure><p>The “Code” in this case it’s all that our function does except the call itself and Base Case.</p><p>This function only exits the Base Case and two calls to the function.</p><h3>Recursion on Stack</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*bUaSeNRwd81kFZ4Z5NH6Gg.png" /></figure><h4>We’ll use the previous function (pow_recursion) to explain what’s happening in the stack.</h4><p>We’ll use: x = 7, y = 5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*Qs_NWdmAKAIRwTFtge0ixw.png" /></figure><p>When we call the function _pow_recursion, we’ll call a total of 5 times the function because we’ve to subtract 1 to the variable “y” by each iteration getting the result of a stack with 5 frames of the same function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*TFJ7PbHz5diEwiaswqoiyQ.png" /></figure><p>After that, we arrived at the Base Case (When “y” is equal to one), at this point, that function returns the number seven.</p><p>And we get to the previous frame where we continue the function since we left it. Multiplying 7 by “x” (x is 7 too). And we’ll do this until the function ends. Getting the result 16870.0!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*TNHVtPIm40TKPGYX0IE0vg.png" /></figure><p>When we end with the functions we’ve finished, we end the recursive function and we get our result. Getting an empty stack!</p><p>And that&#39;s all. I hope this information will be useful to you.</p><p><strong>Thank you for reading.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d1d57260eb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about Dynamic/Shared Libraries in C]]></title>
            <link>https://wardencode.medium.com/all-about-dynamic-shared-libraries-in-c-e6212eff4ef?source=rss-cd7d608392b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6212eff4ef</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[c-language]]></category>
            <category><![CDATA[dynamic-libraries-in-c]]></category>
            <category><![CDATA[gcc]]></category>
            <dc:creator><![CDATA[Diego Jeanluck Linares Castillo]]></dc:creator>
            <pubDate>Tue, 17 May 2022 03:20:32 GMT</pubDate>
            <atom:updated>2022-05-17T03:20:32.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2heGBPWTGNIc3W6-.jpg" /></figure><h3>Types of Libraries</h3><p>Exists two types of libraries on C:</p><ul><li><strong>Static libraries</strong></li><li><strong>Shared / Dynamic libraries</strong></li></ul><p>A <strong>library is just a file that contains a collection of ordinary object files</strong> (.o files) that are linked into the program during the linking phase of the compilation.</p><h3>Why use Libraries?</h3><p><strong>We use libraries to reuse the code</strong> and not go to the directories to copy the code or the same file and paste it into our current file or actual directory.</p><p>So here come libraries to the rescue, <strong>we can use them to access our functionality instead of using a library made by someone else.</strong> If we do this we can write less code and commands as well as get more order in general.</p><blockquote><em>In addition, we can create the libraries mainly to be more organized or to work as a team on large projects it is easier to work using libraries.</em></blockquote><h3>Some disadvantages and advantages about Dynamic/Shared libraries:</h3><h3>Advantages:</h3><ul><li>The <strong>size of executable files is very small</strong> compared to executable files created from static linking</li><li>If <strong>someone make a update/change</strong> to the library <strong>isn’t necessary recompile the program.</strong></li></ul><h3>Disadvantages:</h3><ul><li><strong>The executable depends of the library</strong>, because without the library the program can’t access to the definition of the functions in the <strong>run time process</strong>.</li><li>What happens when we have to call a lot of functions of different libraries and we have to give the program to the costumer. Exactly we have to give him the program and all those libraries. So in that case use Shared / Dynamic libraries is a disadvantage</li></ul><h3>How it’s works?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*cU7mKPE5gmmSvt0ak82D5Q.png" /><figcaption>Dynamic Linking Simplify</figcaption></figure><h3>Dynamic Linking</h3><p>In the <strong>phase of linking</strong>, if we are using a function of a shared library and this function exists in our header file, the <strong>compiler will go to search the dynamic symbol of that function(s) in the dynamic library.</strong></p><blockquote><em>The symbols are the metadata about the address of the object files</em></blockquote><p>To finally <strong>add the address of the function(s) on memory loaded in memory to our source code and get the output of the compiler.</strong> The executable file is in machine code (binary code) with the source code and the address of the function(s).</p><p>In the <strong>run time process</strong> the program have to use the functions of the library, so the program <strong>go to search</strong> <strong>the function(s) in the memory.<br></strong>If the program <strong>doesn’t find the library</strong> will crash.</p><h3>How to create them?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*HY_529PZEQDgsSbyQGUF7A.png" /><figcaption>Simply way to create a Dynamic librarie</figcaption></figure><h3>1. Get The Object code (.o)</h3><p>First, we have to compile our C programs and get the object code (.o files)</p><pre><strong>gcc -c -fPIC *.c</strong></pre><p><strong>This command compiles all .c files of the current directory, stops the compilation before the phase of linking and emit position-independent code, suitable for dynamic linking,</strong> in this way we can get the object code.</p><h3>2. Create the library</h3><pre>gcc -shared -o &lt;name of the library&gt; *.o</pre><p>Well, step by step we are going to understand the snippet of code:</p><ul><li><strong>gcc </strong>= GNU Compiler Collection</li><li><strong>-shared </strong>= This flag produce a shared object which can be linked with other objects to form an executable</li><li><strong>-o</strong> = This flag change the name of the output of the command (by default a.out) but in this case we’ve to set the name of the library.</li><li><strong>&lt;name_of_the_library&gt;</strong> = This can sound obvious but is important for the libraries to use the prefix “lib” and the extension “.so” to use them, so we have to take into account this.</li><li><strong>*.o </strong>= Make reference to all .o files in the current directory</li></ul><h3>3. Check the contents of the library (List the symbols)</h3><p>Here is the last step, after all of this we are going to use the next command on the terminal <strong>“nm”.</strong> <strong>This command list the dynamic symbols from the object files (.o)</strong> or in this case of our library.</p><pre><strong>nm </strong>-D <strong>&lt;name_of_the_library&gt;</strong></pre><p>The flag -D means “Display the dynamic symbols instead the normal symbols”</p><p><strong><em>And that’s all!</em></strong> You created your first dynamic library but that’s not all now we’re going to learn how to use our new library so let’s go for it.</p><h3>How to use them?</h3><p>Well after creating our library we have to use it and for that, we have to use a C file (.c) that uses 1, 2, or more functionalities created by ourselves.</p><p><strong>1. Create our main.h file</strong></p><p>The .h file is an header file, this file contents the prototypes of our programs or even libraries like &lt;stdio.h&gt; or &lt;string.h&gt;, etc.<br>You need to have something like this on your header file.</p><pre>#include &lt;stdlib.h&gt;<br>#include &lt;stdio.h&gt;int _putchar(char c);<br>char *create_array(unsigned int size, char c);<br>char *_strdup(char *str);<br>char *str_concat(char *s1, char *s2);<br>int **alloc_grid(int width, int height);</pre><p>To use this header file we have to use the next line on our C files in case of our header file was called main.h.</p><pre>#include &quot;main.h&quot;</pre><p>After this line, we can use the prototypes (functions) and the above-mentioned libraries.<br>For example:</p><pre>#include &quot;main.h&quot;<br>int main(void)<br>{<br>    printf(&quot;Hello World&quot;);<br>    return (0);<br>}</pre><p>We use the <strong>&lt;stdio.h&gt;</strong> library but in our <strong>C file (.c)</strong> are not included but yes in our header file. But is for that we can use printf because the main.h calls to the <strong>&lt;stdio.h&gt;</strong> library.</p><p><strong>2. Create our test file</strong></p><p>In this step, you need to create a <strong>C file (.c)</strong> that uses the header file and any of the prototypes.</p><p><strong>3. Compile using our library!</strong></p><p>Finally, we’re here so for compile our file using the library using the next command.</p><pre>gcc -L. &lt;.c file&gt; -l&lt;name of shared library&gt;</pre><p>Well, step by step we are going to understand the command:</p><ul><li>gcc = GNU Compiler Collection this is the compiler we’re going to use.</li><li>-L. = This flag is to indicate where the library is located, the dot is for saying that the library is in the current directory.</li><li>-l&lt;name_of_library&gt; = This maybe sounds obvious but this flag indicates that the next command will be a library. You have to write the file the next way (in case of our library’s name is libtest).</li></ul><pre>gcc main.c -L. -ltest</pre><p>We have to write the library this way because the “-l” flag is like that we have lib”…”.a and we have to complete the name of the library, in this case, is with test because the library name is “libtest.so”.</p><p>Visit my other blog if you want to know more about Static Linking / Static Libraries.</p><p><a href="https://wardencode.medium.com/understanding-c-static-libraries-69822228159d">Understanding C Static Libraries</a></p><p>Thank you so much for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6212eff4ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding C Static Libraries]]></title>
            <link>https://wardencode.medium.com/understanding-c-static-libraries-69822228159d?source=rss-cd7d608392b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/69822228159d</guid>
            <category><![CDATA[static-libraries-in-c]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[terminal-commands]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[c-language]]></category>
            <dc:creator><![CDATA[Diego Jeanluck Linares Castillo]]></dc:creator>
            <pubDate>Thu, 03 Mar 2022 00:40:48 GMT</pubDate>
            <atom:updated>2022-05-17T01:44:48.749Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="C Logo" src="https://cdn-images-1.medium.com/max/300/1*8d5jWGRQLBvjf1MKILv0aQ.png" /><figcaption>C Logo</figcaption></figure><p>Before talking about the <strong>Libraries</strong> you must take into account the <strong>process of compilation</strong>. If you don’t know about that I recommend reading this article before this.</p><p><a href="https://wardencode.medium.com/what-happens-behind-when-you-compile-a-c-file-b97c7180237d">What happens behind when you compile a C file?</a></p><p>Well with that into account we are prepared to begin:</p><h4>Types of Libraries</h4><p>Exists two types of libraries on C:</p><ul><li><strong>Static libraries</strong></li><li><strong>Shared / Dynamic libraries</strong></li></ul><p>A <strong>library is just a file that contains a collection of ordinary object files</strong> (.o files) that are linked into the program during the linking phase of the compilation.</p><h3>Why use Libraries?</h3><p><strong>We use libraries to reuse the code</strong> and not go to the directories to copy the code or the same file and paste it into our current file or actual directory.</p><p>So here come libraries to the rescue, <strong>we can use them to access our functionality instead of using a library made by someone else.</strong> If we do this we can write less code and commands as well as get more order in general.</p><blockquote>In addition, we can create the libraries mainly to be more organized or to work as a team on large projects it is easier to work using libraries.</blockquote><h4><strong>Some disadvantages and advantages about static libraries:</strong></h4><h4>Advantage:</h4><ul><li><strong>The executable file doesn’t depend on any library</strong>, you don’t need to install anything to run the program. Gives more portability to a program but at the expense of larger</li></ul><h4>Disadvantages:</h4><ul><li>What happens when we call a lot of functions like 100 or 200, well if we are using static linking (static libraries). The result of this is a<strong> higher size of the resulting executable file.</strong></li><li>Another problem is with the updates to the library if we change a little function of the library <strong>we have to recompile the executable file and update it.</strong></li></ul><h3>How it’s works?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*_sJ5MqGT6FojRu6oVL3FWw.png" /><figcaption>How works the static linking</figcaption></figure><h4>Static Linking</h4><p>In the <strong>phase of linking</strong>, if we are using a function of a static library and this function exists in our header file, the <strong>compiler will go to search the symbol of that function in the static library.</strong></p><blockquote>The symbols are the metadata about the address of the object files</blockquote><p>To finally <strong>add the library code to our source code and get the output of the compiler.</strong> The executable file is in machine code (binary code) with the source code and the library code inside it.</p><h3>How to create them?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*yYf9fwUGXSAg7rw68-AIzQ.png" /><figcaption>Simply way to create a static library</figcaption></figure><h4>1. Get The Object code (.o)</h4><p>First, we have to compile our C programs and get the object code (.o files)</p><pre><strong>gcc *.c -c</strong></pre><p><strong>This command compiles all .c files of the current directory and stops the compilation before the phase of linking</strong>, in this way we can get the object code.</p><h4>2. Create the library</h4><p>For this step, we must <strong>use the command “ar” (archive) in the terminal</strong>.</p><blockquote>Use the command “man ar” for more information.</blockquote><pre><strong>ar -rc *.o &lt;name_of_the_library&gt;</strong></pre><p>Well, step by step we are going to understand the snippet of code:</p><ul><li><strong>ar </strong>= Creates|Modify|Extract form archives.</li><li><strong>-r </strong>= This flag is for replace, in case this flag found some file with the same name and replace it for the recent version.</li><li><strong>-c</strong> = Create, The library will be created without this flag if this file doesn’t exist but appears a message of warning to evade that we use this flag to confirm that we really want to create that library.</li><li><strong>*.o </strong>= Make reference to all .o files in the current directory</li><li><strong>&lt;name_of_the_library&gt;</strong> = This can sound obvious but is important for the libraries to use the prefix “lib” and the extension “.a” to use them, so we have to take into account this.</li></ul><h4>3. Index the library</h4><p><strong>After creating or modifying a library is necessary to index it </strong>we do this with the <strong>command “ranlib”</strong>, this step is important for the compilator because this uses indexes to speed up the search of the symbols on the library and secure their order.<br>To do this we have to use the next command on the terminal.</p><pre><strong>ranlib &lt;name_of_the_library&gt;<br>#or<br>ranlib -t &lt;name_of_the_library&gt;</strong></pre><p>The flag -t is for updating the timestamp of the symbol map of the archive.</p><h4>4. Check the contents of the library (List the symbols)</h4><p>Here is the last step, after all of this we are going to use the next command on the terminal <strong>“nm”.</strong> <strong>This command list the symbols from the object files (.o)</strong> or in this case of our library.</p><pre><strong>nm &lt;name_of_the_library&gt;</strong></pre><p><strong><em>And voila!</em></strong> you created your first library but that’s not all now we’re going to learn how to use our new library so let’s go for it.</p><h3>How to use them?</h3><p>Well after creating our library we have to use it and for that, we have to use a C file (.c) that uses 1, 2, or more functionalities created by ourselves.</p><p><strong>1. Create our main.h file</strong></p><p>The .h file is an header file, this file contents the prototypes of our programs or even libraries like &lt;stdio.h&gt; or &lt;string.h&gt;, etc.<br>You need to have something like this on your header file.</p><pre>#include &lt;stdlib.h&gt;<br>#include &lt;stdio.h&gt;</pre><pre>int _putchar(char c);<br>char *create_array(unsigned int size, char c);<br>char *_strdup(char *str);<br>char *str_concat(char *s1, char *s2);<br>int **alloc_grid(int width, int height);</pre><p>To use this header file we have to use the next line on our C files in case of our header file was called main.h.</p><pre>#include &quot;main.h&quot;</pre><p>After this line, we can use the prototypes (functions) and the above-mentioned libraries.<br>For example:</p><pre>#include &quot;main.h&quot;</pre><pre>int main(void)<br>{<br>    printf(&quot;Hello World&quot;);<br>    return (0);<br>}</pre><p>We use the <strong>&lt;stdio.h&gt;</strong> library but in our <strong>C file (.c)</strong> are not included but yes in our header file. But is for that we can use printf because the main.h calls to the <strong>&lt;stdio.h&gt;</strong> library.</p><p><strong>2. Create our test file</strong></p><p>In this step, you need to create a <strong>C file (.c)</strong> that uses the header file and any of the prototypes.</p><p><strong>3. Compile using our library!</strong></p><p>Finally, we’re here so for compile our file using the library using the next command.</p><pre>gcc &lt;c.file&gt; -L. -l&lt;name_of_library&gt;</pre><p>Well, step by step we are going to understand the command:</p><ul><li>gcc = GNU Compiler Collection this is the compiler we’re going to use.</li><li>-L. = This flag is to indicate where the library is located, the dot is for saying that the library is in the current directory.</li><li>-l&lt;name_of_library&gt; = This maybe sounds obvious but this flag indicates that the next command will be a library. You have to write the file the next way (in case of our library’s name is libtest.a).</li></ul><pre>gcc main.c -L. -ltest</pre><p>We have to write the library this way because the “-l” flag is like that we have lib”…”.a and we have to complete the name of the library, in this case, is with test because the library name is “libtest.a”.</p><p>Thank you so much for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69822228159d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens behind when you compile a C file?]]></title>
            <link>https://wardencode.medium.com/what-happens-behind-when-you-compile-a-c-file-b97c7180237d?source=rss-cd7d608392b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b97c7180237d</guid>
            <category><![CDATA[c-language]]></category>
            <category><![CDATA[gcc]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Diego Jeanluck Linares Castillo]]></dc:creator>
            <pubDate>Thu, 10 Feb 2022 04:32:01 GMT</pubDate>
            <atom:updated>2022-02-11T19:11:14.664Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="GCC logo (GNU Compiler Collection)" src="https://cdn-images-1.medium.com/max/292/1*Ye-V5ySghutZSPhNFEO6IQ.png" /><figcaption>GCC logo</figcaption></figure><p>When we code in C we are looking for efficiency and good control of computer resources but we need to compile the code to use it and for that, we have to use <strong>GCC</strong>.</p><h4>But what is GCC?</h4><p><strong>GCC</strong> is a collection of compilers produced by the GNU project and supports programming languages like<strong> C, C++, Go, Objective-C, Objective-C++, Fortran, Ada, D, etc.</strong></p><p>Having this in mind, we can now talk about the compilation of our <strong>C files </strong>as well as the step-by-step process.</p><h3>First things first, install GCC</h3><p>You have to run the next command on our terminal:</p><pre>sudo apt install gcc</pre><p>To check that you install <strong>GCC</strong> correctly:</p><pre>gcc --version</pre><p>You should have an output like this</p><pre>gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0<br>Copyright (C) 2021 Free Software Foundation, Inc.<br>This is free software; see the source for copying conditions.  There is NO<br>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</pre><p>Now you have <strong>GCC</strong> we can continue.</p><h3>How to Compile a C File?</h3><p>For a basic compile of a <strong>C file</strong> we have to write the next command on our terminal.</p><pre>gcc &lt;filename(s)&gt;</pre><p>After doing this, we get the <strong>a.out</strong> file, this is an executable file and inside it, we will find machine code.</p><p>And that’s it, you were able to compile your first c.</p><h3>That’s all right?</h3><p>Not really, there is more information on how to compile our files as an extended set of options that we will use depending on the situation, the best place to see these options is by using the following command in the terminal.</p><pre>man gcc</pre><p>But also here an example of the syntax</p><pre>gcc [-c|-S|-E] [-std=standard]<br>           [-g] [-pg] [-Olevel]<br>           [-Wwarn...] [-Wpedantic]<br>           [-Idir...] [-Ldir...]<br>           [-Dmacro[=defn]...] [-Umacro]<br>           [-foption...] [-mmachine-option...]<br>           [-o outfile] [<a href="http://twitter.com/file">@file</a>] infile...</pre><h3>Well We’re ready to talks about the behind process of compilation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dx30hLjDxw4x-Rw0m6tFOA.png" /><figcaption>GCC Process</figcaption></figure><p>The compilation process consists of 4 stages to get the long-awaited program in machine code and they are the following.</p><h3>1. Preprocessor:</h3><p>This stage takes the <strong>C files</strong> and is responsible for removing code comments, extends included libraries (i.e. replaces include with library code), replaces macro names with code. Returns the <strong>extended code.</strong></p><p>To see the <strong>extended code</strong> we can use the next flag when are we going to compile the <strong>C file(s).</strong></p><pre>gcc -E &lt;filename&gt;</pre><p>When we use this flag the compiler <strong>return</strong> the result in the <strong>standard output. </strong>You can redirect the result to a file with the next command.</p><pre>gcc -E &lt;filename&gt; &gt; &lt;new_file | another_file_name&gt;</pre><h3>2. Compiler</h3><p>This stage takes the <strong>extended code</strong> and <strong>transforms it into assembly code.</strong></p><p>To see the <strong>Assembly code</strong> we can use the next flag when are we going to compile the <strong>C file(s).</strong></p><pre>gcc -S &lt;filename&gt;</pre><p>When we use this flag the output file will have the extension “.s”.</p><h4><strong>3. Assembler:</strong></h4><p>This stage turns the <strong>Assembly code</strong> and <strong>transforms it into machine code. Returns</strong> the <strong>object code.</strong></p><p>To see the object code we can use the next flag when are we going to compile the <strong>C file(s).</strong></p><pre>gcc -c &lt;filename&gt;</pre><p>When we use this flag the output file will have the extension “.o”.</p><h4><strong>4. Linker:</strong></h4><p>This is the final stage, which is responsible for linking the <strong>object code files</strong> and <strong>merging</strong> them to get the final result of the <strong>compiled file</strong>.</p><p>If the <strong>C file</strong> contains <strong>functions from the library</strong>, the Linker will extract and connect them to the<strong> output file.</strong></p><p>You can see the output using this command after compilation:</p><pre>cat &lt;compiled_file_name&gt;.out</pre><p>When we use this flag the output file will have the extension “.out”.</p><p>Note: You don’t need any flag to obtain the final file.</p><h4>Thanks for reading.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b97c7180237d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s the difference between Hard Links and Symbolic/Soft Links?]]></title>
            <link>https://wardencode.medium.com/whats-the-difference-between-hard-links-and-symbolic-soft-links-7d7d656e305d?source=rss-cd7d608392b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d7d656e305d</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[hard-link]]></category>
            <category><![CDATA[linux-file-system]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[softlink]]></category>
            <dc:creator><![CDATA[Diego Jeanluck Linares Castillo]]></dc:creator>
            <pubDate>Sun, 06 Feb 2022 22:43:26 GMT</pubDate>
            <atom:updated>2022-02-06T22:45:02.020Z</atom:updated>
            <content:encoded><![CDATA[<p>Before to talk about links we’ve to talk about <strong>Inode (Index Node).</strong></p><figure><img alt="Inode Representation" src="https://cdn-images-1.medium.com/max/1024/1*DgxokFMud4JNoAU7JwqCaw.png" /><figcaption>Inode Representation</figcaption></figure><h4>A very shallow summary about “Inode”</h4><p>The linux filesystem is based in <strong>Inode entries </strong>and the <strong>Inode </strong>holds all metadata about the regular files, directories, or any other object that the file system may contain.</p><p>The filenames are in a separate index and linked to the <strong>Inode</strong>, in this way we can create hard link files and give files more than one name.</p><h3>Hard Links</h3><figure><img alt="Hard Links representation" src="https://cdn-images-1.medium.com/max/691/1*7lcoQS8qF5hUmvTW_N4nAg.png" /><figcaption>Hard Links representation</figcaption></figure><p>A <strong>hard link </strong>is a refference or pointer to a file in a filesystem.</p><p><strong>Hard links</strong> associate two or more files sharing the same <strong>Inode</strong>. This makes each <strong>hard link</strong> an exact copy of the rest of the associated files, both data and permissions, owner.</p><p>If you delete the original file unlike <strong>soft/symbolic links</strong>, <strong>hard links</strong> preserve the data, that’s why the <strong>hard links</strong> are the same size.</p><p>Although called differently, both <strong>hard links</strong> and the <strong>original file</strong> offer the same functionality. When modifying the data pointed to by any of them, the real data stored on disk is changed, being modified equally for all.</p><h4>Characteristics:</h4><ul><li>Same <strong>Inode</strong> number that the original file.</li><li>Same file size.</li><li>Different name of the same file.</li><li>Have the same permissions.</li><li>Different of one copy.</li><li>If you change the permissions of the or the <strong>original file</strong> this changes will be applied for both or more if you have more <strong>hard links.</strong></li><li>If you modify the original file or the <strong>hard link</strong> the modify will be apllied for both or more if you have more than one <strong>hard link</strong>.</li></ul><h4>How to create a Hard Link:</h4><pre>$ ln  [original filename] [link name]</pre><h4><strong>What does a hard link look like:</strong></h4><p>They look the same.</p><pre>-rw-rw-rw- 2 root root (date) original_file.txt</pre><pre>-rw-rw-rw- 2 root root (date) hardlinked.txt</pre><h3>Soft Links</h3><figure><img alt="Soft Links representation" src="https://cdn-images-1.medium.com/max/695/1*2iTWTTPuvfpiKNYla82d2w.png" /><figcaption>Soft Links representation</figcaption></figure><p>The <strong>soft/symbolic links</strong> are pointers to another file, you can have more than one <strong>soft/symbolic links</strong> pointing to a same file, if you delete the <strong>principal/original file</strong> all the <strong>soft/symbolic links</strong> are become useless.</p><h4>Characteristics:</h4><ul><li>Is like a shortcut in windows.</li><li>Is a pointer to the original file.</li><li>Each <strong>symbolic/soft</strong> link have a diferent <strong>Inode</strong> number.</li><li>The <strong>symbolic links</strong> have a less size than the <strong>original/principal file</strong>.</li><li>The <strong>soft links</strong> have all permissions.</li></ul><h4>How to create a Soft/Symbolic link</h4><pre>$ ln -s [original filename] [link name]</pre><h4>What does a hard link look like:</h4><p>They look this way.</p><pre>-rw-rw-rw- 1 root root (date) original_file.txt</pre><pre>lrwxrwxrwx 1 root root (date) softlinked.txt -&gt; original_file.txt</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d7d656e305d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>