Skip to content

Commit d6a5fbb

Browse files
committed
feat: new vocab entries
1 parent e6ca1df commit d6a5fbb

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
3+
export default function ModulesVsIncludes() {
4+
return (
5+
<div className="space-y-4">
6+
<p>
7+
<strong>Modules</strong> are independent units of code with explicit interfaces (exports/imports). When imported, the compiler loads a semantic representation of the code, ensuring encapsulation and faster builds.
8+
</p>
9+
10+
<div className="bg-gray-800 p-4 rounded-lg border border-gray-700">
11+
<h4 className="text-sm font-bold text-blue-400 mb-2">
12+
The C Approach (Includes):
13+
</h4>
14+
<p className="text-sm text-gray-300 mb-3">
15+
C lacks modules and relies on the <strong>Preprocessor</strong>.
16+
</p>
17+
<ul className="list-disc pl-5 space-y-2 text-sm text-gray-400">
18+
<li>
19+
<strong className="text-white">Textual Copy-Paste:</strong> <code className="text-pink-400">#include "header.h"</code> literally copies the file's text into your source file.
20+
</li>
21+
<li>
22+
<strong className="text-white">Translation Unit:</strong> The Source file + all copied Headers = one massive unit of code to be compiled.
23+
</li>
24+
<li>
25+
<strong className="text-white">Object Files:</strong> The compiler turns this unit into an Object File (`.o`).
26+
</li>
27+
<li>
28+
<strong className="text-white">Linking:</strong> The Linker stitches these object files together to make the executable.
29+
</li>
30+
</ul>
31+
</div>
32+
33+
<p className="text-sm italic text-gray-500">
34+
This "copy-paste" model is why C builds can be slow (headers are re-parsed every time) and why "include guards" are needed to prevent infinite loops.
35+
</p>
36+
</div>
37+
);
38+
}

src/data/vocab/name-mangling.jsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
3+
export default function NameMangling() {
4+
return (
5+
<div className="space-y-4">
6+
<p>
7+
<strong>Name Mangling</strong> (or name decoration) is a technique used by compilers to resolve unique names for programming entities (like functions, structure members, or variables) in modern programming languages.
8+
</p>
9+
<p>
10+
It provides a way to encode additional information about the name—such as the function's parameter types or scope—directly into the symbol name used by the linker. This is essential for supporting features like function overloading or namespacing, especially in languages like C++.
11+
</p>
12+
<div className="bg-gray-800 p-4 rounded-lg border border-gray-700">
13+
<h4 className="text-sm font-bold text-yellow-400 mb-2">
14+
Example (C++):
15+
</h4>
16+
<p className="text-sm text-gray-400 mb-2">
17+
Two functions with the same name but different arguments:
18+
</p>
19+
<code className="block bg-black p-2 rounded text-xs text-green-400 mb-2">
20+
int foo(int i);<br/>
21+
int foo(char c);
22+
</code>
23+
<p className="text-sm text-gray-400 mb-2">
24+
Might be "mangled" by the compiler into unique symbols like:
25+
</p>
26+
<code className="block bg-black p-2 rounded text-xs text-blue-400">
27+
_Z3fooi // for foo(int)<br/>
28+
_Z3fooc // for foo(char)
29+
</code>
30+
</div>
31+
</div>
32+
);
33+
}

src/data/vocabulary.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@ export const vocabulary = {
5555
title: 'Open Graph Protocol',
5656
loader: () => import('./vocab/open-graph'),
5757
},
58+
'name-mangling': {
59+
title: 'Name Mangling',
60+
loader: () => import('./vocab/name-mangling'),
61+
},
62+
'modules-vs-includes': {
63+
title: 'Modules vs. Includes',
64+
loader: () => import('./vocab/modules-vs-includes'),
65+
},
5866
};

0 commit comments

Comments
 (0)