From 2ef0795bfb440671bffd3c6b93603c012d27c24d Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Mon, 27 Apr 2020 23:23:13 -0600 Subject: [PATCH] Update language reference for recent @Type changes --- doc/langref.html.in | 62 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 3e335c8d64..fa649ebf25 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -1885,7 +1885,7 @@ test "null terminated array" {
  • Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}
  • Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}
  • {#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be - {#syntax#}c_void{#endsyntax#} or any other {#link|@OpaqueType#}.
  • + {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|Opaque Types#}. @@ -5392,7 +5392,7 @@ fn eql_i32(a: i32, b: i32) bool {

    {#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this: - {#syntax#}pub const c_void = @OpaqueType();{#endsyntax#}. + {#syntax#}pub const c_void = @Type(.Opaque);{#endsyntax#}. {#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size.

    @@ -7666,30 +7666,6 @@ mem.set(u8, dest, c);{#endsyntax#}

    {#header_close#} - {#header_open|@OpaqueType#} -
    {#syntax#}@OpaqueType() type{#endsyntax#}
    -

    - Creates a new type with an unknown (but non-zero) size and alignment. -

    -

    - This is typically used for type safety when interacting with C code that does not expose struct details. - Example: -

    - {#code_begin|test_err|expected type '*Derp', found '*Wat'#} -const Derp = @OpaqueType(); -const Wat = @OpaqueType(); - -extern fn bar(d: *Derp) void; -fn foo(w: *Wat) callconv(.C) void { - bar(w); -} - -test "call foo" { - foo(undefined); -} - {#code_end#} - {#header_close#} - {#header_open|@panic#}
    {#syntax#}@panic(message: []const u8) noreturn{#endsyntax#}

    @@ -8274,21 +8250,21 @@ test "integer truncation" {

  • {#syntax#}comptime_float{#endsyntax#}
  • {#syntax#}@TypeOf(undefined){#endsyntax#}
  • {#syntax#}@TypeOf(null){#endsyntax#}
  • +
  • {#link|Arrays#}
  • +
  • {#link|Optionals#}
  • +
  • {#link|Error Union Type#}
  • +
  • {#link|Vectors#}
  • +
  • {#link|Opaque Types#}
  • +
  • AnyFrame
  • For these types it is a TODO in the compiler to implement:

    @@ -8373,6 +8349,28 @@ fn foo(comptime T: type, ptr: *T) T { {#header_close#} {#header_close#} + {#header_open|Opaque Types#} + {#syntax#}@Type(.Opaque){#endsyntax#} creates a new type with an unknown (but non-zero) size and alignment. +

    +

    + This is typically used for type safety when interacting with C code that does not expose struct details. + Example: +

    + {#code_begin|test_err|expected type '*Derp', found '*Wat'#} +const Derp = @Type(.Opaque); +const Wat = @Type(.Opaque); + +extern fn bar(d: *Derp) void; +fn foo(w: *Wat) callconv(.C) void { + bar(w); +} + +test "call foo" { + foo(undefined); +} + {#code_end#} + {#header_close#} + {#header_open|Build Mode#}

    Zig has four build modes: