womangling/lesson-0.html
2025-02-13 23:03:41 +01:00

124 lines
4.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="index.css" />
<title>Womangling</title>
</head>
<body>
<main class="main">
<div class="content" id="content-area">
<h1>
<a class="root-link" href="/">Learn C++ Itanium Symbol Mangling</a>
</h1>
<h2>Lesson 0: Intro and C names</h2>
<noscript>
<p>
Warning: You have JavaScript disabled While the content is still
viewable, interactive exercises will not work. Consider enabling
JavaScript for this website.
</p>
</noscript>
<section data-step="0" class="step">
<p>
Welcome to the interactive Itanium C++ mangling learning website! In
this course you will learn everything there is to know about Itanium
C++ Mangling, especially the things you've never wanted to know.
</p>
<p>
For every exercise, there will be a small quiz. If you complete the
quiz, you can continue
</p>
<div class="quiz-section">
<p>To complete the first quiz, press the button below.</p>
<form data-challenge="1">
<button
data-challenge-submit="1"
class="submit-challenge"
type="submit"
>
Complete first challenge!
</button>
<div class="error"></div>
</form>
</div>
</section>
<section data-step="1" class="step">
<p>
Congrats, you just completed your first challenge! Good job. So,
let's start with the mangling. Before diving too deep into the
innards of Itanium Mangling, let's get more familiar with the way
this works by mangling something trivial: a C function. C functions
are traditionally not mangled (*this is not always fully true on all
platforms). The simplest possible C function takes no arguments and
returns no value. For C it doesn't actually matter what the
parameters or return value are, since there is no mangling.
</p>
<p>
To reference this function in C++, we use an
<code>extern "C"</code> block.
</p>
<pre class="code">
extern "C" {
void hello() {}
}
</pre>
<p>
Because no mangling is applied to the identifier at all, the symbol
for this function will simply be <code>hello</code>.
</p>
<p>
Similarly, a more complex example would be the following function:
</p>
<pre class="code">
extern "C" {
int main(int argc, char* argv[]) {}
}
</pre>
<p>
But once again, the symbol name will simply be
<code>main</code> because no mangling is applied.
</p>
<div class="quiz-section">
<p>What is the mangled symbol of the following function?</p>
<pre class="code">
extern "C" {
long long meow(long long argument, long long second) { /* too long */ }
}
</pre>
<form data-challenge="2" data-answer="meow">
<input class="quiz-input" />
<button
data-challenge-submit="2"
class="submit-challenge"
type="submit"
>
Answer
</button>
<div class="error"></div>
</form>
</div>
</section>
<section data-step="2" class="step">
<p>Congrats on answering your first mangling question!</p>
<p>
You now know how C functions are (not) mangled, which is a great
starting point for your C++ Itanium Symbol Mangling Adventures. I
wish you good luck for the rest!
</p>
<div class="center">
<a href="lesson-1.html" class="action-button">
Lesson 1: Basics
</a>
</div>
</section>
</div>
</main>
<script>
window.LESSON = 0;
</script>
<script type="module" src=".lessons.js"></script>
</body>
</html>