1 <!-- subject: Pro tip: You can put {URLs} in {C} & {C++} code -->
2 <!-- date: 2022-04-01 01:17:43 -->
4 <!-- categories: Misc, Techblog -->
6 <p>Documenting source code is important part of software engineering. Code is
7 read more often than it’s written making it crucial to provide enough context
8 for reader to understand what the implementation is doing. This can come in
9 the form of links to external resources providing description of an algorithm,
10 reference for an API or historic context justifying the code.
12 <p>As it turns out, C and C++ languages offer a little-known feature which
13 allows URLs to be included directly in the function source code. For example:
16 static float rsqrt(float x) {
17 <a href=https://en.wikipedia.org/wiki/Fast_inverse_square_root
>https://en.wikipedia.org/wiki/Fast_inverse_square_root
</a>
18 static_assert(std::numeric_limits
<float
>::is_iec559);
19 auto i = std::bit_cast
<uint32_t
>(x)
>> 1;
20 auto y = std::bit_cast
<float
>(UINT32_C(
0x5F375A86) - i);
21 y *=
1.5f - x *
0.5F * y * y;