Skip to content

Commit

Permalink
const -> var
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Jul 18, 2024
1 parent 2dfb9a3 commit 998bf9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 2024/07/17/advent2023-zig/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ <h3 id="Detectable-Illegal-Behavior"><a href="#Detectable-Illegal-Behavior" clas

<p>This is the best case scenario. A <code>u8</code> can&#39;t represent 256 and Zig has detected this error statically.</p>
<p>If you make the error a little more subtle, though, the Zig compiler can&#39;t see it:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><code class="hljs zig">pub fn main() void &#123;<br> const a: u8 &#x3D; 255;<br> a +&#x3D; 1;<br> std.debug.print(&quot;255 + 1 &#x3D; &#123;d&#125;!\n&quot;, .&#123;a&#125;);<br>&#125;<br></code></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="code"><pre><code class="hljs zig">pub fn main() void &#123;<br> var a: u8 &#x3D; 255;<br> a +&#x3D; 1;<br> std.debug.print(&quot;255 + 1 &#x3D; &#123;d&#125;!\n&quot;, .&#123;a&#125;);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>What happens now is that you get a crash when you <em>run</em> the program:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><code class="hljs plain">$ zig run src&#x2F;main.zig<br>thread 12826611 panic: integer overflow<br>src&#x2F;main.zig:5:7: 0x10031a413 in main (main)<br> a +&#x3D; 1;<br> ^<br></code></pre></td></tr></table></figure>
Expand Down
6 changes: 3 additions & 3 deletions atom.xml

Large diffs are not rendered by default.

0 comments on commit 998bf9b

Please sign in to comment.