<?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"><channel><title><![CDATA[from Zero: What You’ll Find on 0to1]]></title><description><![CDATA[from Zero: What You’ll Find on 0to1]]></description><link>https://from-0-to-1.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 04 Nov 2026 11:23:03 GMT</lastBuildDate><atom:link href="https://from-0-to-1.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How GCC Works: How Different Languages Can Work Together]]></title><description><![CDATA[Learn how GCC compiles code in four stages — preprocessing, compiling, assembling, and linking — and how different languages like C, C++, and Rust cross]]></description><link>https://from-0-to-1.hashnode.dev/how-gcc-works-how-different-languages-can-work-together</link><guid isPermaLink="true">https://from-0-to-1.hashnode.dev/how-gcc-works-how-different-languages-can-work-together</guid><category><![CDATA[#GCC work]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[crosslanguage]]></category><dc:creator><![CDATA[Indrajitsinh Atodariya]]></dc:creator><pubDate>Mon, 04 Aug 2025 13:34:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1754314199431/4f1077fd-c7aa-4888-af03-eed0e1a57138.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">🧠Introduction</h2>
<p>In today’s development world, using multiple programming languages in a single project is quite common. For example, a web application might use <strong>Python (Django)</strong> for the backend, <strong>HTML/CSS</strong> for structure and styling, and <strong>JavaScript</strong> for frontend interactivity. It’s easy to explain this kind of architecture because each language has its own well-defined role in the stack.</p>
<p>But what happens when a project uses <strong>C</strong>, <strong>C++</strong>, <strong>Objective-C</strong>, or even <strong>Go</strong> — all low-level, compiled languages — together in a single system? Unlike web tech stacks, these languages don’t just "run" in the browser or server. They need to be <strong>compiled</strong>, <strong>assembled</strong>, and <strong>linked</strong> into one final binary file — a process that can be both powerful and complex.</p>
<p>So, how does it actually work?<br />How can these different languages — each with its own compiler and build process — produce code that ends up in the <strong>same final executable</strong>?</p>
<p>That’s where tools like <strong>GCC</strong> (GNU Compiler Collection) come into play.</p>
<p>In this blog, I’ll walk you through:</p>
<ul>
<li><p>How GCC compiles code step-by-step (from <code>.c</code> to executable)</p>
</li>
<li><p>How <strong>different languages</strong> can produce compatible outputs like object files (<code>.o</code>)</p>
</li>
<li><p>And how the <strong>linker</strong> is responsible for bringing everything together — or messing it up if you’re not careful</p>
</li>
</ul>
<p>Let’s start from the beginning: the <strong>four main stages of GCC</strong>.</p>
<h2 id="heading-how-gcc-works-the-4-stages-of-compilation">⚙️ How GCC Works: The 4 Stages of Compilation</h2>
<p>The magic of converting source code into an actual executable program doesn’t happen in one step — it’s a pipeline of four key stages. Each stage has a specific role and produces an intermediate file. Let’s break it down:</p>
<h3 id="heading-1-preprocessing-i-file">🧼 1. Preprocessing (<code>.i</code> file)</h3>
<p>This is the <strong>first step</strong>.<br />Here, the GCC preprocessor handles things like:</p>
<ul>
<li><p>Removing comments</p>
</li>
<li><p>Expanding macros (<code>#define</code>)</p>
</li>
<li><p>Including all header files (<code>#include</code>)</p>
</li>
</ul>
<p>After preprocessing, your code is turned into a <strong>plain, expanded version</strong> where all macros and headers are inserted directly into the file. The output is saved as a <code>.i</code> file.</p>
<pre><code class="lang-plaintext">gcc -E file.c -o file.i
</code></pre>
<h3 id="heading-2-compilation-s-file">🛠️ 2. Compilation (<code>.s</code> file)</h3>
<p>Next, the compiler takes the <code>.i</code> file and translates it into <strong>assembly code</strong> — a low-level, human-readable representation of machine instructions.</p>
<p>This stage focuses on:</p>
<ul>
<li><p>Syntax checking</p>
</li>
<li><p>Code optimization</p>
</li>
<li><p>Converting high-level logic into CPU instructions</p>
</li>
</ul>
<p>The output is a <code>.s</code> file (assembly source).</p>
<pre><code class="lang-plaintext">gcc -S file.i -o file.s
</code></pre>
<h3 id="heading-3-assembling-o-file">⚙️ 3. Assembling (<code>.o</code> file)</h3>
<p>The assembler takes the <code>.s</code> file and <strong>translates it into machine code</strong>, but it’s not yet a complete program.<br />This file is called an <strong>object file</strong>, with a <code>.o</code> extension.</p>
<p>At this stage, the code is:</p>
<ul>
<li>In binary form</li>
</ul>
<p>But still missing some parts (like function references from other files or libraries)</p>
<pre><code class="lang-plaintext">gcc -c file.s -o file.o
</code></pre>
<h3 id="heading-4-linking-executable">🔗 4. Linking (Executable)</h3>
<p>Finally, the linker steps in.</p>
<p>It takes all the <code>.o</code> files — including those from your code and any external libraries — and combines them into a single, <strong>fully functional executable</strong>.</p>
<p>This stage:</p>
<ul>
<li><p>Resolves symbol references (e.g., function or variable definitions)</p>
</li>
<li><p>Connects different files together</p>
</li>
<li><p>Handles memory layout</p>
</li>
</ul>
<p>The output is your final program, often named <code>a.out</code> by default.</p>
<pre><code class="lang-plaintext">gcc file.o -o my_program
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754314290727/df9e7f38-e09b-4db7-9bd3-e1e880f535fb.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-dynamic-linking-and-shared-libraries">🔗 Dynamic Linking and Shared Libraries</h2>
<p>In the previous section, we talked about how the linker combines object files into one final executable. But there’s an important distinction to understand here: <strong>static linking</strong> vs <strong>dynamic linking</strong>.</p>
<h3 id="heading-static-linking-brief-recap">📦 Static Linking (Brief Recap)</h3>
<p>In <strong>static linking</strong>, all the code — including functions from external libraries — is bundled <strong>directly into your executable</strong> at compile time.</p>
<ul>
<li><p>✅ No external dependency at runtime</p>
</li>
<li><p>❌ Larger executable file size</p>
</li>
<li><p>❌ Each program has its own copy of the same library (wastes memory)</p>
</li>
</ul>
<h3 id="heading-what-is-dynamic-linking">⚙️ What is Dynamic Linking?</h3>
<p>Dynamic linking solves this by <strong>not copying the actual library code</strong> into your executable. Instead, your executable contains only <strong>references</strong> (or "placeholders") that point to <strong>shared libraries</strong> (usually <code>.so</code> files in Linux) that exist <strong>outside</strong> the program.</p>
<p>At <strong>runtime</strong>, the operating system:</p>
<ul>
<li><p>Loads these shared libraries into memory (if not already loaded)</p>
</li>
<li><p>Links them to your executable while it’s starting up</p>
</li>
<li><p>Resolves any external symbols (like function calls)</p>
</li>
</ul>
<h3 id="heading-example-libc">📂 Example: libc</h3>
<p>Every C/C++ program uses <code>libc</code> — the standard C library.</p>
<ul>
<li><p>In static linking, the entire library is copied into your binary</p>
</li>
<li><p>In dynamic linking, your executable just says:<br />  ➤ “Hey OS, when I run, link me to <code>/lib/</code><a target="_blank" href="http://libc.so"><code>libc.so</code></a><code>.6</code> please.”</p>
</li>
</ul>
<h3 id="heading-how-does-it-help">🧠 How Does It Help?</h3>
<ul>
<li><p>✅ <strong>Reduces executable size</strong> — your program doesn’t carry the full library code</p>
</li>
<li><p>✅ <strong>Memory-efficient</strong> — multiple programs can use the same library already in memory</p>
</li>
<li><p>✅ <strong>Easy updates</strong> — fixing one <code>.so</code> file updates all programs using it</p>
</li>
<li><p>❌ <strong>Dependency risk</strong> — if the <code>.so</code> file is missing or incompatible, the program may crash</p>
</li>
</ul>
<p>Dynamic linking is one of the main reasons why compiled programs today are much more <strong>modular, smaller, and efficient</strong> — especially on systems where many programs share the same system libraries.</p>
<p>Next, we’ll explore <strong>how different languages (like C, C++, Rust, etc.) generate</strong> <code>.o</code> files that the linker can understand — allowing truly mixed-language projects.</p>
<h2 id="heading-how-different-languages-work-together-cross-language-linking">🤝 How Different Languages Work Together: Cross-Language Linking</h2>
<p>You might wonder: how can a single program be written in <strong>C</strong>, <strong>C++</strong>, <strong>Rust</strong>, and <strong>Assembly</strong>, and still work as one unified system?</p>
<p>The secret is this:</p>
<blockquote>
<p><strong>All these languages eventually compile down to object files (</strong><code>.o</code>) — and the linker doesn't care which language they came from, as long as the format and rules are followed.</p>
</blockquote>
<h3 id="heading-the-common-ground-object-files-o">🔧 The Common Ground: Object Files (<code>.o</code>)</h3>
<p>Regardless of the source language, once the code is compiled, it becomes an object file that:</p>
<ul>
<li><p>Uses a standard format (like ELF in Linux)</p>
</li>
<li><p>Contains machine code</p>
</li>
<li><p>Includes metadata like function names, variables, and memory layout</p>
</li>
</ul>
<p>As long as each language’s compiler generates object files that follow the <strong>same ABI (Application Binary Interface)</strong>, they can be <strong>linked together</strong> into a single executable.</p>
<h3 id="heading-real-world-example-c-c">🧩 Real-World Example: C + C++</h3>
<p>C++ has features like classes and function overloading that C doesn’t understand. But with <code>extern "C"</code>, you can tell the C++ compiler:</p>
<blockquote>
<p>“Compile this part as if it’s in C.”</p>
</blockquote>
<pre><code class="lang-plaintext">// C++ file
extern "C" {
    void hello_from_c();
}

int main() {
    hello_from_c();
    return 0;
}
</code></pre>
<pre><code class="lang-plaintext">// C file
#include &lt;stdio.h&gt;
void hello_from_c() {
    printf("Hello from C!\n");
}
</code></pre>
<pre><code class="lang-plaintext">gcc -c hello.c -o hello.o
g++ -c main.cpp -o main.o
g++ main.o hello.o -o output
</code></pre>
<p>✅ One final executable, made from both C and C++.</p>
<h2 id="heading-common-issues-memory-errors-and-wrapping-up"><strong>common issues, memory errors, and wrapping up</strong></h2>
<h3 id="heading-common-pitfalls-in-cross-language-linking-amp-memory-management">⚠️ Common Pitfalls in Cross-Language Linking &amp; Memory Management</h3>
<p>While combining code from different languages sounds exciting, it often leads to subtle and hard-to-debug issues if you’re not careful. Below are some of the most common problems you might encounter:</p>
<h3 id="heading-1-symbol-mismatches">❌ 1. Symbol Mismatches</h3>
<p>Each compiler may <strong>name</strong> functions differently in the object files (this is called <em>name mangling</em>). For example:</p>
<ul>
<li><p>C++ mangles names to support function overloading</p>
</li>
<li><p>C does not</p>
</li>
</ul>
<p><strong>Fix</strong>: Use <code>extern "C"</code> in C++ to make symbols C-compatible.</p>
<h3 id="heading-2-calling-convention-conflicts">❌ 2. Calling Convention Conflicts</h3>
<p>Every language might use a slightly different rule for how:</p>
<ul>
<li><p>Arguments are passed (stack/register)</p>
</li>
<li><p>Return values are handled</p>
</li>
<li><p>The stack is cleaned up</p>
</li>
</ul>
<p><strong>Fix</strong>: Make sure both sides (caller &amp; callee) use the same <strong>calling convention</strong> and match the function signature exactly.</p>
<h3 id="heading-3-struct-misalignment-or-padding">❌ 3. Struct Misalignment or Padding</h3>
<p>Different compilers (or even the same compiler in different modes) might lay out <strong>structs</strong> differently in memory.</p>
<p>This can cause:</p>
<ul>
<li><p>Garbage values</p>
</li>
<li><p>Crashes due to misaligned memory access</p>
</li>
</ul>
<p><strong>Fix</strong>: Use fixed-size data types (<code>int32_t</code>, <code>uint8_t</code>) and <code>#pragma pack</code> or alignment attributes when needed.</p>
<h3 id="heading-4-memory-ownership-confusion">❌ 4. Memory Ownership Confusion</h3>
<p>When one language allocates memory and another frees it, you can get:</p>
<ul>
<li><p>Double free errors</p>
</li>
<li><p>Memory leaks</p>
</li>
<li><p>Segmentation faults</p>
</li>
</ul>
<p><strong>Fix</strong>: Define a clear contract about who allocates and who frees memory.</p>
<h2 id="heading-conclusion">🧠 Conclusion</h2>
<p>Understanding how <strong>GCC works behind the scenes</strong> gives you a deeper appreciation for what’s really happening when you hit “compile.”</p>
<p>From preprocessing to linking, each stage plays a critical role in transforming source code into a working program.</p>
<p>And when it comes to using multiple languages in a single project — whether it’s <strong>C, C++, Rust, Go, or Assembly</strong> — the real challenge isn’t writing the code… it’s making sure the output files can safely work together.</p>
<blockquote>
<p>💡 One bad <code>.o</code> file with a wrong assumption about memory, naming, or calling convention can break your entire system.</p>
</blockquote>
<p>So next time you’re debugging a strange runtime crash or missing function — look deeper. It might just be your <strong>linker trying to tell you something</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[0to1 — A Student’s Learning Journey]]></title><description><![CDATA[A student’s blog sharing learning from CS, web development, math, and more — growing from 0 to 1, one concept at a time.]]></description><link>https://from-0-to-1.hashnode.dev/0to1-a-students-learning-journey</link><guid isPermaLink="true">https://from-0-to-1.hashnode.dev/0to1-a-students-learning-journey</guid><category><![CDATA[Learning Journey]]></category><dc:creator><![CDATA[Indrajitsinh Atodariya]]></dc:creator><pubDate>Sun, 03 Aug 2025 12:48:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1754225689345/6b7ff41b-66bc-48d7-b4e5-e02a1d1656e3.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-welcome-to-0to1-a-students-learning-blog">Welcome to 0to1 — A Student’s Learning Blog</h2>
<p>Hey there! 👋</p>
<p>Welcome to <strong>0to1</strong> — a space where I share the things I learn, explore, and find interesting as a student.</p>
<p>I started this blog to document my learning journey. I’m not an expert — I’m just someone who enjoys figuring things out and writing them down in a way others (especially beginners) might find helpful. Whether it’s a concept I finally understood, a project I worked on, or just something that caught my attention, I’ll share it here in the simplest way possible.</p>
<hr />
<h3 id="heading-what-to-expect">What to Expect</h3>
<p>On this blog, you’ll find posts about:</p>
<ul>
<li><p>Topics I’m learning in <strong>computer science</strong> and <strong>development</strong></p>
</li>
<li><p><strong>Maths</strong>, <strong>logic</strong>, or even <strong>physics</strong> ideas that make me think</p>
</li>
<li><p>Errors I fix, tools I try, and insights I gain along the way</p>
</li>
<li><p>Anything that helps me grow from knowing nothing to knowing something</p>
</li>
</ul>
<p>This is not a niche blog. It’s just <strong>a student’s notebook, shared publicly</strong>.</p>
<hr />
<h3 id="heading-why-0to1">Why “0to1”?</h3>
<p>Because every learning journey starts at zero.<br />And this blog is my way of going from 0 to 1 — one small step at a time.</p>
<p>If you're learning too, struggling to understand new concepts, or just curious like me — I hope you’ll find something relatable here.</p>
<p>Thanks for visiting. More posts coming soon! 🌱</p>
]]></content:encoded></item></channel></rss>