<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
  <title>bd103.dev</title>
  <link>https://aggr.aymericbeaumet.com/sources/bd103.dev/</link>
  <description>Browse aymeric&#39;s, an independent, searchable archive of readable snapshots from followed feeds, preserved in Git with aggr.</description>
  <language>en</language>
  <atom:link href="https://aggr.aymericbeaumet.com/sources/bd103.dev/rss.xml" rel="self" type="application/rss+xml"/>
  <lastBuildDate>Wed, 7 Oct 2026 14:30:05 +0000</lastBuildDate>
  <generator>aggr</generator>
  <item>
    <title>C for Rust Programmers</title>
    <link>https://aggr.aymericbeaumet.com/items/lobste-rs/2026-10-07-c-for-rust-programmers/</link>
    <guid isPermaLink="false">urn:aggr:item:ddde640d64bfcdafde9cf3b1e58dd0513c3adcd4</guid>
    <atom:link href="https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/" rel="via" type="text/html"/>
    <pubDate>Wed, 7 Oct 2026 14:30:05 +0000</pubDate>
    <dc:creator>bd103.dev by BD103</dc:creator>
    <description>Comments</description>
    <content:encoded>&lt;p&gt;The very first systems programming language I ever learned was Rust. This is uncommon compared to many other programmers; you&#39;re more likely to find someone who learned C or C++ first before coming to Rust. As such, there are plenty of &amp;quot;Rust for C Programmers&amp;quot; articles on the internet, but little to no &amp;quot;C for Rust Programmers&amp;quot; articles out there.&lt;/p&gt;
&lt;p&gt;Well, I&#39;m about to change that! I&#39;ve been learning C and C++ recently, and &lt;em&gt;holy cow those languages are quirky&lt;/em&gt;. This blog post is a collection of eyebrow-raising details I learned while teaching myself C. (No C++ today, I&#39;m not ready to dig into that can of worms.) This is not a substitute for a proper C tutorial, you&#39;ll need to Google one of those yourself. Rather, it&#39;s a list of things to keep in mind when working in the language.&lt;/p&gt;
&lt;p&gt;With the premise set, let&#39;s draw the curtain and see what C has to offer!&lt;/p&gt;
&lt;h2&gt;Boolean Is Not* Built-In&lt;/h2&gt;
&lt;p&gt;The original version of C did not have a primitive type for booleans, programs instead used the integers 0 and 1. This was changed in &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://en.wikipedia.org/wiki/C99&quot;&gt;C99&lt;/a&gt;, which added booleans in the optional &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://en.cppreference.com/c/header/stdbool&quot;&gt;&lt;code&gt;&amp;lt;stdbool.h&amp;gt;&lt;/code&gt;&lt;/a&gt; header &lt;sup class=&quot;citation-ref&quot;&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fn-_bool&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-preprocessor syntax-include syntax-c&quot;&gt;&lt;span class=&quot;syntax-keyword syntax-control syntax-import syntax-include syntax-c&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;syntax-string syntax-quoted syntax-other syntax-lt-gt syntax-include syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;lt;&lt;/span&gt;stdbool.h&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-entity syntax-name syntax-function syntax-c&quot;&gt;main&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;
    &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;bool&lt;/span&gt; yes &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-language syntax-c&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;bool&lt;/span&gt; no &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-language syntax-c&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;syntax-keyword syntax-control syntax-c&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Even still, &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; are not literals or keywords like in other languages. Instead, they are definitions that expand to 1 and 0:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-preprocessor syntax-macro syntax-c&quot;&gt;&lt;span class=&quot;syntax-keyword syntax-control syntax-import syntax-define syntax-c&quot;&gt;#define&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-preprocessor syntax-macro syntax-c&quot;&gt; &lt;span class=&quot;syntax-entity syntax-name syntax-constant syntax-preprocessor syntax-c&quot;&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-preprocessor syntax-macro syntax-c&quot;&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-preprocessor syntax-macro syntax-c&quot;&gt;&lt;span class=&quot;syntax-keyword syntax-control syntax-import syntax-define syntax-c&quot;&gt;#define&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-preprocessor syntax-macro syntax-c&quot;&gt; &lt;span class=&quot;syntax-entity syntax-name syntax-constant syntax-preprocessor syntax-c&quot;&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-preprocessor syntax-macro syntax-c&quot;&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This was changed again in &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://en.wikipedia.org/wiki/C23_(C_standard_revision)&quot;&gt;C23&lt;/a&gt;&lt;sup class=&quot;citation-ref&quot;&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fn-c23&quot;&gt;[2]&lt;/a&gt;&lt;/sup&gt;, so now booleans are true language primitives, but if you&#39;re compiling for earlier versions you&#39;ll need to include &lt;code&gt;&amp;lt;stdbool.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Null-Terminated Strings&lt;/h2&gt;
&lt;p&gt;A Rust &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://doc.rust-lang.org/stable/std/primitive.str.html&quot;&gt;&lt;code&gt;&amp;amp;str&lt;/code&gt;&lt;/a&gt; is 16 bytes: 8 bytes for the memory address and 8 bytes for the string length. This is because &lt;code&gt;str&lt;/code&gt; is a dynamically sized type, and uses &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2023-08-06-ptr-metadata/&quot;&gt;pointer metadata&lt;/a&gt; to track the length of the string.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;Rust&quot;&gt;&lt;span class=&quot;syntax-source syntax-rust&quot;&gt;&lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-rust&quot;&gt;//&lt;/span&gt; While a normal reference uses only 8 bytes...
&lt;/span&gt;&lt;span class=&quot;syntax-support syntax-macro syntax-rust&quot;&gt;assert_eq!&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-path syntax-rust&quot;&gt;std&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-rust&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-path syntax-rust&quot;&gt;mem&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-rust&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-path syntax-rust&quot;&gt;size_of&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-rust&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-generic syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-begin syntax-rust&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-rust&quot;&gt;u8&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-end syntax-rust&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-rust&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-integer syntax-decimal syntax-rust&quot;&gt;8&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-rust&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-rust&quot;&gt;//&lt;/span&gt; ...strings use 16 bytes.
&lt;/span&gt;&lt;span class=&quot;syntax-support syntax-macro syntax-rust&quot;&gt;assert_eq!&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-path syntax-rust&quot;&gt;std&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-rust&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-path syntax-rust&quot;&gt;mem&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-rust&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-path syntax-rust&quot;&gt;size_of&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-rust&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-generic syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-begin syntax-rust&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-rust&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-end syntax-rust&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-rust&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-integer syntax-decimal syntax-rust&quot;&gt;16&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-rust&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This approach makes fetching the string length extremely efficient, but requires more memory per &lt;code&gt;&amp;amp;str&lt;/code&gt; reference. C uses a different approach: it doesn&#39;t store the size of its strings separately, but instead terminates every single string with a null byte (&lt;code&gt;\0&lt;/code&gt;). This is an intentional trade off that results in a few things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;C programs don&#39;t need to keep track of an extra &lt;code&gt;size&lt;/code&gt; variable alongside the string&lt;/li&gt;
&lt;li&gt;Every single string needs room at the end for a null byte
&lt;ul&gt;
&lt;li&gt;This means empty strings &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; still take up one byte of memory!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Null bytes cannot easily be used in the middle of a string without messing up &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/header/string&quot;&gt;&lt;code&gt;&amp;lt;string.h&amp;gt;&lt;/code&gt;&lt;/a&gt;&#39;s functions&lt;/li&gt;
&lt;li&gt;Forgetting the null terminator can result in out-of-bound reads&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In practice, this requires you to remember to allocate extra space for the null terminator and insert it at the end of strings. For example, here is a program that reverses a string in C:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt; 1char&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-entity syntax-name syntax-function syntax-c&quot;&gt;reverse&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;syntax-variable syntax-parameter syntax-c&quot;&gt;forward&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;
 &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-c&quot;&gt;//&lt;/span&gt; Calculate the string&amp;#39;s length, excluding the null terminator.
&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;3&lt;/span&gt;    &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;long&lt;/span&gt; len &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;strlen&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;forward&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
 &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;4&lt;/span&gt;    &lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-c&quot;&gt;//&lt;/span&gt; Allocate enough room for the string and its null terminator.
&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;5&lt;/span&gt;    &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; reversed &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;len &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
 &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;6&lt;/span&gt;
 &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;7&lt;/span&gt;    &lt;span class=&quot;syntax-keyword syntax-control syntax-c&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;int&lt;/span&gt; i &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;syntax-keyword syntax-operator syntax-comparison syntax-c&quot;&gt;&amp;lt;&lt;/span&gt; len&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;8&lt;/span&gt;        reversed&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; forward&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;len &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;-&lt;/span&gt; i&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
 &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;9&lt;/span&gt;    &lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;11&lt;/span&gt;    &lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-c&quot;&gt;//&lt;/span&gt; Add the null terminator at the end.
&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;12&lt;/span&gt;    reversed&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;len&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-string syntax-quoted syntax-single syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-character syntax-escape syntax-c&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;13&lt;/span&gt;
&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;14&lt;/span&gt;    &lt;span class=&quot;syntax-keyword syntax-control syntax-c&quot;&gt;return&lt;/span&gt; reversed&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;15&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note lines 5 and 12, which take special measure to account for the null terminator. For reference, the corresponding Rust function &lt;sup class=&quot;citation-ref&quot;&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fn-rust-reverse-string&quot;&gt;[4]&lt;/a&gt;&lt;/sup&gt; doesn&#39;t need to do so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;Rust&quot;&gt;&lt;span class=&quot;syntax-source syntax-rust&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-rust&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-rust&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-function syntax-rust&quot;&gt;fn&lt;/span&gt; &lt;/span&gt;&lt;span class=&quot;syntax-entity syntax-name syntax-function syntax-rust&quot;&gt;reverse&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-rust&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-parameters syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-variable syntax-parameter syntax-rust&quot;&gt;forward&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-rust&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;&amp;amp;&lt;/span&gt;[&lt;span class=&quot;syntax-storage syntax-type syntax-rust&quot;&gt;u8&lt;/span&gt;]&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-rust&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-parameters syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-rust&quot;&gt; &lt;span class=&quot;syntax-meta syntax-function syntax-return-type syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-rust&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-generic syntax-rust&quot;&gt;Box&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-begin syntax-rust&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-rust&quot;&gt;u8&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-end syntax-rust&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-rust&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-rust&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;syntax-storage syntax-type syntax-rust&quot;&gt;let&lt;/span&gt; len &lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;=&lt;/span&gt; forward.&lt;span class=&quot;syntax-support syntax-function syntax-rust&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-rust&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;syntax-storage syntax-type syntax-rust&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;syntax-storage syntax-modifier syntax-rust&quot;&gt;mut&lt;/span&gt; reversed &lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-support syntax-type syntax-rust&quot;&gt;Box&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-rust&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-rust&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-generic syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-begin syntax-rust&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-rust&quot;&gt;u8&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-generic syntax-end syntax-rust&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-path syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-rust&quot;&gt;::&lt;/span&gt;&lt;/span&gt;new_uninit_slice&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;len&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-rust&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;syntax-keyword syntax-control syntax-rust&quot;&gt;for&lt;/span&gt; i &lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-integer syntax-decimal syntax-rust&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;..&lt;/span&gt;len &lt;span class=&quot;syntax-meta syntax-block syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-rust&quot;&gt;{&lt;/span&gt;
        reversed&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;]&lt;/span&gt;&lt;/span&gt;.&lt;span class=&quot;syntax-support syntax-function syntax-rust&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;forward&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;[&lt;/span&gt;len &lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-integer syntax-decimal syntax-rust&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-rust&quot;&gt;-&lt;/span&gt; i&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-rust&quot;&gt;;&lt;/span&gt;
    &lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-rust&quot;&gt;}&lt;/span&gt;&lt;/span&gt;

    &lt;span class=&quot;syntax-storage syntax-modifier syntax-rust&quot;&gt;unsafe&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-rust&quot;&gt;{&lt;/span&gt; reversed.&lt;span class=&quot;syntax-support syntax-function syntax-rust&quot;&gt;assume_init&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-rust&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-rust&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-rust&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-rust&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-rust&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Target-Dependent Integer Widths&lt;/h2&gt;
&lt;p&gt;C&#39;s integer types are not guaranteed to use an exact number of bits, instead the width varies depending on the target platform.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;C Standard&lt;/th&gt;
&lt;th&gt;64-bit Unix&lt;/th&gt;
&lt;th&gt;64-bit Windows&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;char&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;at least 8 bits&lt;/td&gt;
&lt;td&gt;8 bits&lt;/td&gt;
&lt;td&gt;8 bits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;short&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;at least 16 bits&lt;/td&gt;
&lt;td&gt;16 bits&lt;/td&gt;
&lt;td&gt;16 bits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;int&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;at least 16 bits&lt;/td&gt;
&lt;td&gt;32 bits&lt;/td&gt;
&lt;td&gt;32 bits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;long&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;at least 32 bits&lt;/td&gt;
&lt;td&gt;64 bits&lt;/td&gt;
&lt;td&gt;32 bits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;long long&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;at least 64 bits&lt;/td&gt;
&lt;td&gt;64 bits&lt;/td&gt;
&lt;td&gt;64 bits&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Data sourced &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/language/arithmetic_types&quot;&gt;via cppreference.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;long&lt;/code&gt; being 64 bits on Unix and 32 bits on Windows particularly irks me. I recommend following the advice that &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://github.com/magicalbat&quot;&gt;a friend of mine&lt;/a&gt; gave me a few years ago: if you care about cross-platform compatibility, only use the fixed width integers provided by &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/header/stdint&quot;&gt;&lt;code&gt;&amp;lt;stdint.h&amp;gt;&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;th&gt;C&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;u8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;uint8_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;u16&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;uint16_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;u32&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;uint32_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;u64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;uint64_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;usize&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;size_t&lt;/code&gt;&lt;sup class=&quot;citation-ref&quot;&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fn-size_t-and-ptrdiff_t&quot;&gt;[5]&lt;/a&gt;&lt;/sup&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;i8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int8_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;i16&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int16_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;i32&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int32_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;i64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int64_t&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;isize&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ptrdiff_t&lt;/code&gt;&lt;sup class=&quot;citation-ref&quot;&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fn-size_t-and-ptrdiff_t&quot;&gt;[5]&lt;/a&gt;&lt;/sup&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Error Handling Sucks&lt;/h2&gt;
&lt;p&gt;I really love Rust&#39;s error handling. &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://doc.rust-lang.org/stable/std/result/enum.Result.html&quot;&gt;&lt;code&gt;Result&lt;/code&gt;&lt;/a&gt; forces you to address errors, and sum types (&lt;code&gt;enum&lt;/code&gt;s) and &lt;code&gt;match&lt;/code&gt; statements make doing so really easy!&lt;/p&gt;
&lt;p&gt;C&#39;s error handling story, in comparison, is straight up tragic. It seems to boil down to functions returning a &amp;quot;magic integer&amp;quot; like -1 or a null pointer to signal there was an error. You can get a little bit more information by reading &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/error/errno&quot;&gt;&lt;code&gt;errno&lt;/code&gt;&lt;/a&gt;, a thread-local integer that can be used to check for specific kinds of errors, but in terms of getting actual error messages and stack traces it is much harder.&lt;/p&gt;
&lt;p&gt;When writing C, one of the biggest things you&#39;ll notice is that the language will never force you to handle errors. It&#39;s up to you to remember that functions can fail. For example, here&#39;s a snippet of code from &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#null-terminated-strings&quot;&gt;Null-Terminated Strings&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-c&quot;&gt;//&lt;/span&gt; Allocate enough room for the string and its null terminator.
&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; reversed &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;len &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-keyword syntax-control syntax-c&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;int&lt;/span&gt; i &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;syntax-keyword syntax-operator syntax-comparison syntax-c&quot;&gt;&amp;lt;&lt;/span&gt; len&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;
    reversed&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; forward&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;len &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;-&lt;/span&gt; i&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To new programmers, it&#39;s not immediately obvious that &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/memory/malloc&quot;&gt;&lt;code&gt;malloc()&lt;/code&gt;&lt;/a&gt; can fail and return a null pointer. If your machine runs out of memory, &lt;code&gt;reversed[i]&lt;/code&gt; will cause a segfault upon being accessed. In order to avoid unhelpful segfaults, the program should check for a null pointer and gracefully exit if one is found:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; reversed &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;len &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-keyword syntax-control syntax-c&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;reversed &lt;span class=&quot;syntax-keyword syntax-operator syntax-comparison syntax-c&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-language syntax-c&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;perror&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;Error&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Doing so provides a much better experience than a segfault, or worse, other unintentional behavior:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shellscript&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;Shell&quot;&gt;&lt;span class=&quot;syntax-source syntax-shell syntax-bash&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;$&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; ./main&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;Error:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; Cannot allocate memory&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, remembering to check every single allocated pointer isn&#39;t an amazing developer experience. An approach I played around with was recreating Rust&#39;s &lt;code&gt;Result&lt;/code&gt; in C using tagged unions:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-struct syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;syntax-entity syntax-name syntax-struct syntax-c&quot;&gt;MallocResult&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-struct syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;
    &lt;span class=&quot;syntax-meta syntax-enum syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;syntax-entity syntax-name syntax-enum syntax-c&quot;&gt;Tag&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-enum syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt; OK&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; ERROR &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-enum syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; tag&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;syntax-meta syntax-union syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;union&lt;/span&gt; &lt;span class=&quot;syntax-entity syntax-name syntax-union syntax-c&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-union syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;
        &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; ptr&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; error_message&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-union syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; value&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-struct syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It&#39;s a complete mess to use, however, and there&#39;s &lt;em&gt;still&lt;/em&gt; nothing stopping you from immediately accessing &lt;code&gt;result.value.ptr&lt;/code&gt; without handling the error first. The lack of visibility modifiers like &lt;code&gt;private&lt;/code&gt; and &lt;code&gt;public&lt;/code&gt;, which could be used to prevent this, appear to be an intentional design decision. C places full trust in the programmer to &lt;em&gt;do things right™&lt;/em&gt; and gives few facilities for contracts or safe abstractions.&lt;/p&gt;
&lt;p&gt;I personally disagree with this approach. I&#39;m not some mastermind programming wizard who never makes mistakes. I&#39;d much rather encode program requirements into the type system so that the compiler can check them for me!&lt;sup class=&quot;citation-ref&quot;&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fn-fearless-simd&quot;&gt;[6]&lt;/a&gt;&lt;/sup&gt; That way, I can be reasonably certain that if the code compiles it was written correctly. But I digress.&lt;/p&gt;
&lt;h2&gt;Field Access Syntax&lt;/h2&gt;
&lt;p&gt;C has two different field access operators: &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/language/operator_member_access#Member_access&quot;&gt;&lt;code&gt;.&lt;/code&gt;&lt;/a&gt; for values and &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/language/operator_member_access#Member_access_through_pointer&quot;&gt;&lt;code&gt;-&amp;gt;&lt;/code&gt;&lt;/a&gt; for pointers.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-struct syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;syntax-entity syntax-name syntax-struct syntax-c&quot;&gt;Foo&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-struct syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;
    &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;int&lt;/span&gt; field&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-struct syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;struct&lt;/span&gt; Foo value &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;103&lt;/span&gt; &lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;struct&lt;/span&gt; Foo&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; ptr &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;&amp;amp;&lt;/span&gt;value&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-c&quot;&gt;//&lt;/span&gt; Accessing the field directly.
&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-c&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-other syntax-placeholder syntax-c&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-character syntax-escape syntax-c&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; value&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-c&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;syntax-variable syntax-other syntax-member syntax-c&quot;&gt;field&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-c&quot;&gt;//&lt;/span&gt; Accessing the field through a pointer.
&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-c&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-other syntax-placeholder syntax-c&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-character syntax-escape syntax-c&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; ptr&lt;span class=&quot;syntax-punctuation syntax-accessor syntax-c&quot;&gt;-&amp;gt;&lt;/span&gt;field&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This caught me off guard at first, as Rust uses &lt;code&gt;.&lt;/code&gt; for everything.&lt;/p&gt;
&lt;p&gt;&lt;picture class=&quot;article-picture article-picture-fallback&quot; style=&quot;--image-ratio:16 / 9&quot;&gt;&lt;img src=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/i-put-that-dot-on-everything.jpg&quot; alt=&quot;An old lady holding Frank&amp;#39;s Red Hot sauce, except Ferris the crab is photoshopped on top saying &amp;#39;I put that . on everything&amp;#39;&quot; loading=&quot;eager&quot; decoding=&quot;async&quot; fetchpriority=&quot;high&quot; referrerpolicy=&quot;no-referrer&quot; class=&quot;progressive-image&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;If your curious, &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://stackoverflow.com/a/13366168&quot;&gt;this Stack Overflow write up&lt;/a&gt; provides some interesting history on why the &lt;code&gt;-&amp;gt;&lt;/code&gt; operator exists.&lt;sup class=&quot;citation-ref&quot;&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fn-cursed-arrow-operator&quot;&gt;[7]&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;h2&gt;Arrays Become Pointers for Fun&lt;/h2&gt;
&lt;p&gt;Arrays have some weird nuance to them. Sometimes they are plain values with their length accessible using &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/language/sizeof&quot;&gt;&lt;code&gt;sizeof()&lt;/code&gt;&lt;/a&gt;, other times they are pointers with an unknown size. In general, this is determined by whether you are handling the array within the function it was defined or not.&lt;/p&gt;
&lt;p&gt;To showcase what I mean, here&#39;s a very simple C program that prints the size of two arrays:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt; declared_size&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt; inferred_size&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;6&lt;/span&gt; &lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-c&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;Declared size (main): &lt;span class=&quot;syntax-constant syntax-other syntax-placeholder syntax-c&quot;&gt;%ld&lt;/span&gt; bytes&lt;span class=&quot;syntax-constant syntax-character syntax-escape syntax-c&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-c&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;declared_size&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-c&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;Inferred size (main): &lt;span class=&quot;syntax-constant syntax-other syntax-placeholder syntax-c&quot;&gt;%ld&lt;/span&gt; bytes&lt;span class=&quot;syntax-constant syntax-character syntax-escape syntax-c&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-c&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;inferred_size&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When run, this programs tells you that both arrays take 3 bytes of memory. Good!&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shellscript&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;Shell&quot;&gt;&lt;span class=&quot;syntax-source syntax-shell syntax-bash&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;$&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; ./main&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;Declared&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; size (main&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-post-cmd syntax-shell&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-colon syntax-shell&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; 3 bytes&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;Inferred&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; size (main&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-post-cmd syntax-shell&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-colon syntax-shell&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; 3 bytes&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, let&#39;s make a slight modification. Let&#39;s pass &lt;code&gt;declared_size&lt;/code&gt; and &lt;code&gt;inferred_size&lt;/code&gt; through a function before printing its size:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-entity syntax-name syntax-function syntax-c&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;syntax-variable syntax-parameter syntax-c&quot;&gt;declared_size&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;syntax-variable syntax-parameter syntax-c&quot;&gt;inferred_size&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt; &lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;
    &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;Declared size (function): &lt;span class=&quot;syntax-constant syntax-other syntax-placeholder syntax-c&quot;&gt;%ld&lt;/span&gt; bytes&lt;span class=&quot;syntax-constant syntax-character syntax-escape syntax-c&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-c&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;declared_size&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-C99 syntax-c&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;Inferred size (function): &lt;span class=&quot;syntax-constant syntax-other syntax-placeholder syntax-c&quot;&gt;%ld&lt;/span&gt; bytes&lt;span class=&quot;syntax-constant syntax-character syntax-escape syntax-c&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-c&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-c&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;inferred_size&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;None of the logic changed, the arrays are identical to the previous example, however now the program reports each array takes &lt;strong&gt;8 bytes of memory&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shellscript&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;Shell&quot;&gt;&lt;span class=&quot;syntax-source syntax-shell syntax-bash&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;$&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; ./main&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;Declared&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; size (function&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-post-cmd syntax-shell&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-colon syntax-shell&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; 8 bytes&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;Inferred&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; size (function&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-post-cmd syntax-shell&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-support syntax-function syntax-colon syntax-shell&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; 8 bytes&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Why? Because any array passed through a function is &lt;em&gt;implicitly converted&lt;/em&gt; to a pointer to the first element. From the C compiler&#39;s perspective, the above function actually had the following type signature:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function syntax-c&quot;&gt;&lt;span class=&quot;syntax-entity syntax-name syntax-function syntax-c&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function syntax-parameters syntax-c&quot;&gt;&lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;syntax-variable syntax-parameter syntax-c&quot;&gt;declared_size&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;syntax-variable syntax-parameter syntax-c&quot;&gt;inferred_size&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is why it confusingly looked like each array was 8 bytes long. The arrays themselves are 3 bytes, but the pointers take up 8 bytes of memory! Handily, Clang raises a warning when you run &lt;code&gt;sizeof()&lt;/code&gt; on the pointer form of an array, making it easier to catch this mistake:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shellscript&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;Shell&quot;&gt;&lt;span class=&quot;syntax-source syntax-shell syntax-bash&quot;&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;$&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; clang main.c&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;06-arrays/main.c:5:59:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; warning: sizeof on array function parameter will return size of &lt;span class=&quot;syntax-string syntax-quoted syntax-single syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;char *&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;instead&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; of &lt;span class=&quot;syntax-string syntax-quoted syntax-single syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;char[3]&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-begin syntax-shell&quot;&gt;[&lt;/span&gt;-Wsizeof&lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-shell&quot;&gt;-&lt;/span&gt;array&lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-shell&quot;&gt;-&lt;/span&gt;argument&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-end syntax-shell&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;5&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell&quot;&gt;|&lt;/span&gt;     &lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;printf&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt;(&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell&quot;&gt;&amp;quot;&lt;/span&gt;Declared size (function): %ld bytes\n&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, sizeof(declared_size&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-post-cmd syntax-shell&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-post-cmd syntax-shell&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-logical syntax-continue syntax-shell&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell&quot;&gt;|&lt;/span&gt;                                                           &lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;06-arrays/main.c:4:20:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; note: declared here&lt;/span&gt;
    &lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;4&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-logical syntax-pipe syntax-shell&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-function-call syntax-shell&quot;&gt;&lt;span class=&quot;syntax-variable syntax-function syntax-shell&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-meta syntax-function-call syntax-arguments syntax-shell&quot;&gt; function(char declared_size&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-begin syntax-shell&quot;&gt;[&lt;/span&gt;3&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-end syntax-shell&quot;&gt;]&lt;/span&gt;, char inferred_size&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-begin syntax-shell&quot;&gt;[&lt;/span&gt;]) &lt;span class=&quot;syntax-meta syntax-group syntax-expansion syntax-brace syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-expansion syntax-brace syntax-begin syntax-shell&quot;&gt;{&lt;/span&gt;
      |                    ^
06-arrays/main.c:6:59: warning: sizeof on array function parameter will return size of &lt;span class=&quot;syntax-string syntax-quoted syntax-single syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;char *&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
      instead of &lt;span class=&quot;syntax-string syntax-quoted syntax-single syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;char[]&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-begin syntax-shell&quot;&gt;[&lt;/span&gt;-Wsizeof&lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-shell&quot;&gt;-&lt;/span&gt;array&lt;span class=&quot;syntax-keyword syntax-operator syntax-word syntax-shell&quot;&gt;-&lt;/span&gt;argument&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-end syntax-shell&quot;&gt;]&lt;/span&gt;
    6 |     printf(&lt;span class=&quot;syntax-string syntax-quoted syntax-double syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-begin syntax-shell&quot;&gt;&amp;quot;&lt;/span&gt;Inferred size (function): %ld bytes\n&lt;span class=&quot;syntax-punctuation syntax-definition syntax-string syntax-end syntax-shell&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-shell&quot;&gt;,&lt;/span&gt; sizeof(inferred_size));
      |                                                           ^
06-arrays/main.c:4:43: note: declared here
    4 | void function(char declared_size&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-begin syntax-shell&quot;&gt;[&lt;/span&gt;3&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-end syntax-shell&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-shell&quot;&gt;,&lt;/span&gt; char inferred_size&lt;span class=&quot;syntax-keyword syntax-control syntax-regexp syntax-set syntax-begin syntax-shell&quot;&gt;[&lt;/span&gt;]) &lt;span class=&quot;syntax-meta syntax-group syntax-expansion syntax-brace syntax-shell&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-expansion syntax-brace syntax-begin syntax-shell&quot;&gt;{&lt;/span&gt;
      |                                           ^
2 warnings generated.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Oh Yeah References Don&#39;t Exist&lt;/h2&gt;
&lt;p&gt;I&#39;d be remiss if I didn&#39;t mention it once. C has no borrow checking, and no concept of references. It&#39;s all &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://doc.rust-lang.org/stable/std/primitive.pointer.html&quot;&gt;raw pointers&lt;/a&gt;. This means you can do fun pointer arithmetic like so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;code-snippet&quot; data-language=&quot;C&quot;&gt;&lt;span class=&quot;syntax-source syntax-c&quot;&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;int&lt;/span&gt; array&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-separator syntax-c&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;syntax-comment syntax-line syntax-double-slash syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-definition syntax-comment syntax-c&quot;&gt;//&lt;/span&gt; Woah, iterating over pointers instead of indexes!
&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-control syntax-c&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-group syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-begin syntax-c&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;syntax-storage syntax-type syntax-c&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt; x &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;&amp;amp;&lt;/span&gt;array&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt; x &lt;span class=&quot;syntax-keyword syntax-operator syntax-comparison syntax-c&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;&amp;amp;&lt;/span&gt;array&lt;span class=&quot;syntax-meta syntax-brackets syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-begin syntax-c&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-brackets syntax-end syntax-c&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt; x&lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-group syntax-end syntax-c&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;syntax-meta syntax-block syntax-c&quot;&gt;&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-begin syntax-c&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt;x &lt;span class=&quot;syntax-keyword syntax-operator syntax-assignment syntax-c&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;syntax-constant syntax-numeric syntax-c&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-arithmetic syntax-c&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;syntax-keyword syntax-operator syntax-c&quot;&gt;*&lt;/span&gt;x&lt;span class=&quot;syntax-punctuation syntax-terminator syntax-c&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;syntax-punctuation syntax-section syntax-block syntax-end syntax-c&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, I&#39;m not sure how good an idea that is. 😅&lt;/p&gt;
&lt;p&gt;Either way, be careful when you mess with pointers. Making mistakes with memory results in buffer overflows and out-of-bounds writes, which provide significant threats to the security of your code.&lt;/p&gt;
&lt;p&gt;&lt;picture class=&quot;article-picture article-picture-fallback&quot; style=&quot;--image-ratio:16 / 9&quot;&gt;&lt;img src=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/vuln-categories-2021.png&quot; alt=&quot;A graph visualizing which vulnerability category had the most CVEs between November 2021 and January 2022. Buffer overflow is the third most common, with 346 CVEs, and out-of-bounds writes are the ninth most common, with 204 CVEs. The two categories more common than buffer overflow are denial-of-service with 488 and cross-site scripting with 683.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;low&quot; referrerpolicy=&quot;no-referrer&quot; class=&quot;progressive-image&quot;&gt;&lt;/picture&gt;&lt;/p&gt;
&lt;p&gt;Vulnerability category distribution for CVEs registered between Nov. 2021 and Jan. 2022, &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://unit42.paloaltonetworks.com/network-security-trends-cross-site-scripting/&quot;&gt;via&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I hope you enjoyed this article! I&#39;ve honestly had a lot of fun learning C. And while I doubt I&#39;ll reach for it for personal projects, it&#39;s absolutely a crucial language to know as a systems programmer. All the examples in this blog are &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://github.com/BD103/C-for-Rust-Programmers&quot;&gt;available on Github&lt;/a&gt;, if you&#39;d like to mess with them yourself!&lt;/p&gt;
&lt;p&gt;Until next time,&lt;/p&gt;
&lt;p&gt;- BD103 :)&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Technically you can use &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://en.cppreference.com/c/keyword/_Bool&quot;&gt;&lt;code&gt;_Bool&lt;/code&gt;&lt;/a&gt; without the header, but you still need it for the &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; definitions. &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fr-_bool-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It looks like &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://clang.llvm.org/c_status.html&quot;&gt;Clang still has only partial support for C23&lt;/a&gt;, so you may need to wait a little while longer before chucking away your &lt;code&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;/code&gt; statements. &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fr-c23-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The corresponding Rust function is not idiomatic, and can only correctly handle ASCII text. If I were writing a production version of this function, it would be a single line of code: &lt;code&gt;forward.chars().rev().collect::&amp;lt;String&amp;gt;()&lt;/code&gt;. &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fr-rust-reverse-string-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://doc.rust-lang.org/stable/std/primitive.usize.html&quot;&gt;&lt;code&gt;usize&lt;/code&gt;&lt;/a&gt; and &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://doc.rust-lang.org/stable/std/primitive.isize.html&quot;&gt;&lt;code&gt;isize&lt;/code&gt;&lt;/a&gt; don&#39;t perfectly map semantically to &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/types/size_t&quot;&gt;&lt;code&gt;size_t&lt;/code&gt;&lt;/a&gt; and &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://cppreference.com/c/types/ptrdiff_t&quot;&gt;&lt;code&gt;ptrdiff_t&lt;/code&gt;&lt;/a&gt;. I don&#39;t fully understand the difference, however, so I recommend doing your own research before using these types. &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fr-size_t-and-ptrdiff_t-1&quot;&gt;↩&lt;/a&gt; &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fr-size_t-and-ptrdiff_t-2&quot;&gt;↩2&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://shnatsel.github.io/safe-simd-in-rust-even-on-the-inside/&quot;&gt;This blog post on Fearless SIMD&lt;/a&gt; provides a great example of using Rust&#39;s type system to guarantee the correctness of code. I highly recommend giving it a read! &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fr-fearless-simd-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;My favorite line of code from that post is &lt;code&gt;100-&amp;gt;a = 0;&lt;/code&gt;, it&#39;s so cursed! &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/#fr-cursed-arrow-operator-1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
</content:encoded>
    <category>news</category>
    <category>c</category>
    <category>rust</category>
  </item>
</channel>
</rss>
