clarify const variables in docs

closes #1200
This commit is contained in:
Andrew Kelley 2018-09-03 12:18:12 -04:00
parent 2a9329c998
commit 3f273479f8
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C

View File

@ -566,7 +566,7 @@ const c_string_literal =
{#header_close#}
{#header_close#}
{#header_open|Assignment#}
<p>Use <code>const</code> to assign a value to an identifier:</p>
<p>Use the <code>const</code> keyword to assign a value to an identifier:</p>
{#code_begin|test_err|cannot assign to constant#}
const x = 1234;
@ -582,7 +582,8 @@ test "assignment" {
foo();
}
{#code_end#}
<p>If you need a variable that you can modify, use <code>var</code>:</p>
<p><code>const</code> applies to all of the bytes that the identifier immediately addresses. {#link|Pointers#} have their own const-ness.</p>
<p>If you need a variable that you can modify, use the <code>var</code> keyword:</p>
{#code_begin|test#}
const assert = @import("std").debug.assert;
@ -1918,7 +1919,7 @@ test "linked list" {
assert(list2.first.?.data == 1234);
}
{#code_end#}
{#header_open|struct naming#}
{#header_open|struct Naming#}
<p>Since all structs are anonymous, Zig infers the type name based on a few rules.</p>
<ul>
<li>If the struct is in the initialization expression of a variable, it gets named after