authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-26 09:05:11-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-06 22:08:29-06:00
log6b8ae6fffb71128169de447851244869aebb882b
tree74039c5f75002c6f2ec4ec1d2c98278e2a59c2fa
parent0a563902305369ca298f5b2d360be55f4d5a95e8
signaturelock-open Commit is signed but in an unrecognized format.

langref: update for opaque {} syntax


2 files changed, 9 insertions(+), 7 deletions(-)

doc/docgen.zig+1
...@@ -808,6 +808,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:...@@ -808,6 +808,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
808 .Keyword_noalias,808 .Keyword_noalias,
809 .Keyword_noinline,809 .Keyword_noinline,
810 .Keyword_nosuspend,810 .Keyword_nosuspend,
811 .Keyword_opaque,
811 .Keyword_or,812 .Keyword_or,
812 .Keyword_orelse,813 .Keyword_orelse,
813 .Keyword_packed,814 .Keyword_packed,
doc/langref.html.in+8-7
...@@ -1988,7 +1988,7 @@ test "null terminated array" {...@@ -1988,7 +1988,7 @@ test "null terminated array" {
1988 <li>Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}</li>1988 <li>Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}</li>
1989 <li>Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}</li>1989 <li>Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}</li>
1990 <li>{#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be1990 <li>{#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be
1991 {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|Opaque Types#}.</li>1991 {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|opaque#}.</li>
1992 </ul>1992 </ul>
1993 </li>1993 </li>
1994 </ul>1994 </ul>
...@@ -5545,7 +5545,7 @@ test "turn HashMap into a set with void" {...@@ -5545,7 +5545,7 @@ test "turn HashMap into a set with void" {
5545 </p>5545 </p>
5546 <p>5546 <p>
5547 {#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this:5547 {#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this:
5548 {#syntax#}pub const c_void = @Type(.Opaque);{#endsyntax#}.5548 {#syntax#}pub const c_void = opaque {};{#endsyntax#}.
5549 {#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size.5549 {#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size.
5550 </p>5550 </p>
5551 <p>5551 <p>
...@@ -8471,7 +8471,7 @@ test "integer truncation" {...@@ -8471,7 +8471,7 @@ test "integer truncation" {
8471 <li>{#link|Error Set Type#}</li>8471 <li>{#link|Error Set Type#}</li>
8472 <li>{#link|Error Union Type#}</li>8472 <li>{#link|Error Union Type#}</li>
8473 <li>{#link|Vectors#}</li>8473 <li>{#link|Vectors#}</li>
8474 <li>{#link|Opaque Types#}</li>8474 <li>{#link|opaque#}</li>
8475 <li>{#link|@Frame#}</li>8475 <li>{#link|@Frame#}</li>
8476 <li>{#syntax#}anyframe{#endsyntax#}</li>8476 <li>{#syntax#}anyframe{#endsyntax#}</li>
8477 <li>{#link|struct#}</li>8477 <li>{#link|struct#}</li>
...@@ -8547,17 +8547,18 @@ fn foo(comptime T: type, ptr: *T) T {...@@ -8547,17 +8547,18 @@ fn foo(comptime T: type, ptr: *T) T {
8547 {#header_close#}8547 {#header_close#}
8548 {#header_close#}8548 {#header_close#}
85498549
8550 {#header_open|Opaque Types#}8550 {#header_open|opaque#}
8551 <p>8551 <p>
8552 {#syntax#}@Type(.Opaque){#endsyntax#} creates a new type with an unknown (but non-zero) size and alignment.8552 {#syntax#}opaque {}{#endsyntax#} declares a new type with an unknown (but non-zero) size and alignment.
8553 It can have declarations like structs, unions, or enums.
8553 </p>8554 </p>
8554 <p>8555 <p>
8555 This is typically used for type safety when interacting with C code that does not expose struct details.8556 This is typically used for type safety when interacting with C code that does not expose struct details.
8556 Example:8557 Example:
8557 </p>8558 </p>
8558 {#code_begin|test_err|expected type '*Derp', found '*Wat'#}8559 {#code_begin|test_err|expected type '*Derp', found '*Wat'#}
8559const Derp = @Type(.Opaque);8560const Derp = opaque {};
8560const Wat = @Type(.Opaque);8561const Wat = opaque {};
85618562
8562extern fn bar(d: *Derp) void;8563extern fn bar(d: *Derp) void;
8563fn foo(w: *Wat) callconv(.C) void {8564fn foo(w: *Wat) callconv(.C) void {