From 3f273479f8f38fb408181b2ae2fff1acf4278ba1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 3 Sep 2018 12:18:12 -0400 Subject: [PATCH] clarify const variables in docs closes #1200 --- doc/langref.html.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 97263347c7..bebbdaaa13 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -566,7 +566,7 @@ const c_string_literal = {#header_close#} {#header_close#} {#header_open|Assignment#} -

Use const to assign a value to an identifier:

+

Use the const keyword to assign a value to an identifier:

{#code_begin|test_err|cannot assign to constant#} const x = 1234; @@ -582,7 +582,8 @@ test "assignment" { foo(); } {#code_end#} -

If you need a variable that you can modify, use var:

+

const applies to all of the bytes that the identifier immediately addresses. {#link|Pointers#} have their own const-ness.

+

If you need a variable that you can modify, use the var keyword:

{#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#}

Since all structs are anonymous, Zig infers the type name based on a few rules.