<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <title>Event Horizon of Thought</title>
  <subtitle>The limits of language mean the limits of the world.</subtitle>
  <link href="https://blog.1248369.xyz/index.html"/>
  <link rel="self" href="https://blog.1248369.xyz/feed.xml"/>
  <id>https://blog.1248369.xyz/</id>
  <updated>2026-10-15T00:00:00Z</updated>
  <author><name>Wei</name></author>
  <entry>
    <title>cpp standard and compiler</title>
    <link href="https://blog.1248369.xyz/posts/cpp-standard-and-compiler.html"/>
    <id>https://blog.1248369.xyz/posts/cpp-standard-and-compiler.html</id>
    <published>2026-10-15T00:00:00Z</published>
    <updated>2026-10-15T00:00:00Z</updated>
    <author><name>Wei</name></author>
    <category term="c++"/>
    <summary>To use update-alternatives to manage your g++ versions, you must first ensure a newer compiler (like GCC 11) is installed, register both versions with the system, and then selec…</summary>
    <content type="html" xml:base="https://blog.1248369.xyz/posts/cpp-standard-and-compiler.html">&lt;p&gt;To use update-alternatives to manage your g++ versions, you must first ensure a newer compiler (like GCC 11) is installed, register both versions with the system, and then select the new default.
Here is the step-by-step process to set it up and verify it with a test compilation.&lt;/p&gt;
&lt;h1&gt;GCC to Default C++ Standard Mapping&lt;/h1&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;G++ Version&lt;/th&gt;
&lt;th&gt;Default C++ Standard Flag&lt;/th&gt;
&lt;th&gt;Base ISO Standard&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;G++ 16&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-std=gnu++20&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;C++20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G++ 11 to 15&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-std=gnu++17&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;C++17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G++ 6 to 10&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-std=gnu++14&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;C++14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G++ 5 and older&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-std=gnu++98&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;C++98 / C++03&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h1&gt;Install g++&lt;/h1&gt;
&lt;h2&gt;Step 1: Install a newer compiler and register both versions&lt;/h2&gt;
&lt;p&gt;Run the following commands to install g++-11 and add both your current g++ and the new g++-11 to the update-alternatives system.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# 1. Add the toolchain test repository
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y

# 2. Update your package lists to pull in the new repository data
sudo apt update

# 3. Install GCC 11
sudo apt update &amp;amp;&amp;amp; sudo apt install g++-11 -y

# 4. Register your current system g++ (typically pointing to g++-9 on Ubuntu 20.04)
# We assign it a priority of 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 50

# 5. Register the new g++-11 with a higher priority of 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100

# 6. Register the new g++-16 with a higher priority of 150
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-16 150
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Note: If your original compiler is not version 9, replace /usr/bin/g++-9 above with your actual version, which you can find by running ls /usr/bin/g++*).&lt;/p&gt;
&lt;h2&gt;Step 2: Choose your default version&lt;/h2&gt;
&lt;p&gt;If you ever want to manually toggle back and forth between them later, run this command:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;sudo update-alternatives --config g++
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You will see a menu like this.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Type the selection number for g++-11 and press Enter:
text
  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/g++-11    100       auto mode
  1            /usr/bin/g++-9     50        manual mode
  2            /usr/bin/g++-11    100       manual mode

Press &amp;lt;enter&amp;gt; to keep the current choice[*], or type selection number:

&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Step 3: Verify by checking the macro and compiling&lt;/h2&gt;
&lt;p&gt;Now, let&amp;#x27;s verify that your system defaults to the new version and can natively compile C++20 without changing any flags.&lt;/p&gt;
&lt;h3&gt;Check the new default macro standard&lt;/h3&gt;
&lt;p&gt;Run your macro query again. It should now output 201703L (C++17) as the bare default:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;echo | g++ -dM -E -x c++ - | grep __cplusplus
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;• 202002L indicates C++20
• 201703L indicates C++17
• 201402L indicates C++14
• 201103L indicates C++11
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Test a C++20 compilation using the standard flag&lt;/h3&gt;
&lt;p&gt;Because g++-11 recognizes the finalized standard, your previous one-liner with -std=c++20 will now compile and execute flawlessly:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;echo -e &amp;#x27;#include &amp;lt;iostream&amp;gt;\nint main() {\n    std::cout &amp;lt;&amp;lt; &amp;quot;Hello from C++20!&amp;quot; &amp;lt;&amp;lt; std::endl;\n    return 0;\n}&amp;#x27; &amp;gt; main.cpp &amp;amp;&amp;amp; g++ -std=c++20 main.cpp -o program &amp;amp;&amp;amp; ./program
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Test a C++20 compilation using c++20 feature:&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;echo -e &amp;#x27;#include &amp;lt;iostream&amp;gt;\n#include &amp;lt;concepts&amp;gt;\n\ntemplate&amp;lt;typename T&amp;gt;\nconcept Numeric = std::integral&amp;lt;T&amp;gt; || std::floating_point&amp;lt;T&amp;gt;;\n\nvoid print_val(Numeric auto x) {\n    std::cout &amp;lt;&amp;lt; &amp;quot;Native C++20 Concept Works! Value: &amp;quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; std::endl;\n}\n\nint main() {\n    print_val(2026);\n    return 0;\n}&amp;#x27; &amp;gt; main.cpp &amp;amp;&amp;amp; g++ main.cpp -o program &amp;amp;&amp;amp; ./program
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <title>Secret2</title>
    <link href="https://blog.1248369.xyz/posts/secret.html"/>
    <id>https://blog.1248369.xyz/posts/secret.html</id>
    <published>2026-10-15T00:00:00Z</published>
    <updated>2026-10-15T00:00:00Z</updated>
    <author><name>Wei</name></author>
    <summary>Input password 1234</summary>
    <content type="html" xml:base="https://blog.1248369.xyz/posts/secret.html">&lt;p&gt;Input password 1234&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Markdown showcase</title>
    <link href="https://blog.1248369.xyz/posts/markdown-showcase.html"/>
    <id>https://blog.1248369.xyz/posts/markdown-showcase.html</id>
    <published>2026-10-14T00:00:00Z</published>
    <updated>2026-10-14T00:00:00Z</updated>
    <author><name>Wei</name></author>
    <category term="markdown"/>
    <category term="reference"/>
    <summary>A tour of the syntax this blog understands: CommonMark plus the GitHub-flavoured extensions MD4C implements.</summary>
    <content type="html" xml:base="https://blog.1248369.xyz/posts/markdown-showcase.html">&lt;p&gt;A tour of the syntax this blog understands: CommonMark plus the
GitHub-flavoured extensions MD4C implements.&lt;/p&gt;
&lt;h2&gt;Inline formatting&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Emphasis&lt;/em&gt;, &lt;strong&gt;strong&lt;/strong&gt;, &lt;em&gt;&lt;strong&gt;both&lt;/strong&gt;&lt;/em&gt;, &lt;del&gt;strikethrough&lt;/del&gt;, &lt;code&gt;inline code&lt;/code&gt;,
&lt;mark&gt;highlight&lt;/mark&gt;, and a &lt;a href=&quot;https://commonmark.org&quot;&gt;link&lt;/a&gt;. Bare URLs such as
&lt;a href=&quot;https://github.com/mity/md4c&quot;&gt;https://github.com/mity/md4c&lt;/a&gt; become links automatically.&lt;/p&gt;
&lt;h2&gt;Lists&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;First&lt;/li&gt;
&lt;li&gt;Second&lt;ul&gt;
&lt;li&gt;Nested bullet&lt;/li&gt;
&lt;li&gt;Another one&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Third&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled checked&gt;Task lists&lt;/li&gt;
&lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled&gt;with checkboxes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Code&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const md4c = await loadMd4c();
console.log(md4c.toHtml(&amp;#x27;# Hello&amp;#x27;));
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Tables&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;left&quot;&gt;Feature&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Flag&lt;/th&gt;
&lt;th align=&quot;center&quot;&gt;Default&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Tables&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;TABLES&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;center&quot;&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Strikethrough&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;STRIKETHROUGH&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;center&quot;&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Wiki links&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;WIKILINKS&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;center&quot;&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Underline&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;&lt;code&gt;UNDERLINE&lt;/code&gt;&lt;/td&gt;
&lt;td align=&quot;center&quot;&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Quotes and admonitions&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Markdown is intended to be as easy-to-read and easy-to-write as is
feasible.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;admonition-note&quot;&gt;&lt;p class=&quot;admonition-title&quot;&gt;note&lt;/p&gt;&lt;p&gt;Admonitions use GitHub&amp;#x27;s &lt;code&gt;&amp;gt; [!NOTE]&lt;/code&gt; syntax.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;admonition-warning&quot;&gt;&lt;p class=&quot;admonition-title&quot;&gt;warning&lt;/p&gt;&lt;p&gt;Anything uploaded to the public bucket can be read by anyone with its URL,
so keep drafts on your own machine.&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;Mathematics&lt;/h2&gt;
&lt;p&gt;Inline mathematics such as &lt;x-equation&gt;e^{i\pi} + 1 = 0&lt;/x-equation&gt; and display equations are
typeset with KaTeX, which is loaded only for posts that contain math:&lt;/p&gt;
&lt;p&gt;&lt;x-equation type=&quot;display&quot;&gt; \hat{f}(\xi) = \int_{-\infty}^{\infty} f(x)\, e^{-2\pi i x \xi}\, dx &lt;/x-equation&gt;&lt;/p&gt;
&lt;p&gt;The cost of parsing a document of &lt;x-equation&gt;n&lt;/x-equation&gt; bytes is &lt;x-equation&gt;O(n)&lt;/x-equation&gt; for typical input.&lt;/p&gt;
&lt;h2&gt;Footnotes&lt;/h2&gt;
&lt;p&gt;MD4C supports footnotes&lt;sup&gt;&lt;a href=&quot;#fn-1&quot; id=&quot;fnref-1-1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;, and links between posts like &lt;a href=&quot;welcome.html&quot;&gt;Welcome&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;That&amp;#x27;s the tour.&lt;/p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol&gt;
&lt;li id=&quot;fn-1&quot;&gt;
Rendered at the bottom of the post, with a link back.&lt;a href=&quot;#fnref-1-1&quot; class=&quot;footnote-backref&quot;&gt;&amp;#8617;&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
  </entry>
  <entry>
    <title>How it works</title>
    <link href="https://blog.1248369.xyz/posts/how-it-works.html"/>
    <id>https://blog.1248369.xyz/posts/how-it-works.html</id>
    <published>2026-10-13T00:00:00Z</published>
    <updated>2026-10-13T00:00:00Z</updated>
    <author><name>Wei</name></author>
    <category term="meta"/>
    <category term="wasm"/>
    <category term="storage"/>
    <summary>This blog has four layers, shown below from storage to screen.</summary>
    <content type="html" xml:base="https://blog.1248369.xyz/posts/how-it-works.html">&lt;p&gt;This blog has four layers, shown below from storage to screen.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;figure-pipeline.svg&quot; alt=&quot;The rendering pipeline: Markdown fetched from read-only storage is parsed by md4c.wasm in the reader&amp;#x27;s browser and the resulting HTML is sanitised before display.&quot;&gt;&lt;/p&gt;
&lt;h2&gt;MD4C as WebAssembly&lt;/h2&gt;
&lt;p&gt;The C parser and HTML renderer from &lt;code&gt;src/&lt;/code&gt; are compiled with plain
&lt;code&gt;clang --target=wasm32&lt;/code&gt;. A tiny freestanding libc (&lt;code&gt;wasm/libc/&lt;/code&gt;) supplies
&lt;code&gt;malloc&lt;/code&gt;, &lt;code&gt;memcpy&lt;/code&gt;, &lt;code&gt;snprintf&lt;/code&gt; and friends, so neither Emscripten nor a WASI
SDK is needed. The module is about 130 KB and exports one real function:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;int md4c_wasm_to_html(const char* input, unsigned input_size,
                      unsigned parser_flags, unsigned renderer_flags);
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;A file system made of storagesdk&lt;/h2&gt;
&lt;p&gt;The native &lt;code&gt;md2html&lt;/code&gt; reads and writes files with stdio. A browser has no
files, so &lt;code&gt;wasm/js/md4c-fs.js&lt;/code&gt; provides &lt;code&gt;readFile&lt;/code&gt;, &lt;code&gt;readdir&lt;/code&gt;, &lt;code&gt;renderFile&lt;/code&gt;
and friends on top of &lt;a href=&quot;https://github.com/storagesdk/storagesdk&quot;&gt;storagesdk&lt;/a&gt;.
In the browser it uses a read-only adapter that fetches files from a plain
public URL, such as a Cloudflare R2 bucket.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Path&lt;/th&gt;
&lt;th&gt;Contents&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;index.json&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the list of posts, with title/date/tags&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;posts/&amp;lt;slug&amp;gt;.md&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Markdown source with front matter&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Read-only for everyone but the owner&lt;/h2&gt;
&lt;p&gt;Visitors only ever see the bucket&amp;#x27;s public URL, which accepts reads and
nothing else. The owner publishes from their own machine with
&lt;code&gt;scripts/publish.mjs&lt;/code&gt;, which writes through any storagesdk adapter (R2, S3,
a local folder, ...) using credentials only they have. Rendered HTML is
also cleaned by DOMPurify, under a strict Content-Security-Policy.&lt;/p&gt;
&lt;h2&gt;The blog itself&lt;/h2&gt;
&lt;p&gt;A few hundred lines of plain JavaScript: a hash router, a post list and a
post view. Its appearance — title, slogan, theme, colours, background image
— is configured in the &lt;code&gt;site&lt;/code&gt; section of &lt;code&gt;index.json&lt;/code&gt;.&lt;sup&gt;&lt;a href=&quot;#fn-1&quot; id=&quot;fnref-1-1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol&gt;
&lt;li id=&quot;fn-1&quot;&gt;
Every post is rendered when you open it. MD4C is fast enough that
this usually takes well under a millisecond.&lt;a href=&quot;#fnref-1-1&quot; class=&quot;footnote-backref&quot;&gt;&amp;#8617;&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
  </entry>
  <entry>
    <title>Welcome</title>
    <link href="https://blog.1248369.xyz/posts/welcome.html"/>
    <id>https://blog.1248369.xyz/posts/welcome.html</id>
    <published>2026-10-12T00:00:00Z</published>
    <updated>2026-10-12T00:00:00Z</updated>
    <author><name>Wei</name></author>
    <category term="meta"/>
    <category term="intro"/>
    <summary>Welcome! Every page you see was rendered from Markdown on your own machine by MD4C, compiled to WebAssembly. There is no server code at all: the posts are plain files in read-on…</summary>
    <content type="html" xml:base="https://blog.1248369.xyz/posts/welcome.html">&lt;p&gt;Welcome! Every page you see was rendered from Markdown on your own machine
by &lt;a href=&quot;https://github.com/mity/md4c&quot;&gt;MD4C&lt;/a&gt;, compiled to WebAssembly. There is
no server code at all: the posts are plain files in read-only storage.&lt;/p&gt;
&lt;h2&gt;What you can do&lt;/h2&gt;
&lt;ul&gt;
&lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled checked&gt;Read the sample posts&lt;/li&gt;
&lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled&gt;Follow a tag&lt;/li&gt;
&lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled&gt;Jump between posts with wiki links&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Anyone can read; only the blog owner, who holds the storage credentials,
can publish. To learn how the pieces fit together, read
&lt;a href=&quot;how-it-works.html&quot;&gt;How it works&lt;/a&gt;. To see what the renderer supports, open the
&lt;a href=&quot;markdown-showcase.html&quot;&gt;Markdown showcase&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;admonition-tip&quot;&gt;&lt;p class=&quot;admonition-title&quot;&gt;tip&lt;/p&gt;&lt;p&gt;You can edit your document on the local machine then upload to draft storage like r2 or webdav.&lt;/p&gt;
&lt;/div&gt;
</content>
  </entry>
</feed>
