| ... | ... | @@ -1885,7 +1885,7 @@ test "null terminated array" { |
| 1885 | 1885 | <li>Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}</li> |
| 1886 | 1886 | <li>Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}</li> |
| 1887 | 1887 | <li>{#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be |
| 1888 | | {#syntax#}c_void{#endsyntax#} or any other {#link|@OpaqueType#}.</li> |
| 1888 | {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|Opaque Types#}.</li> |
| 1889 | 1889 | </ul> |
| 1890 | 1890 | </li> |
| 1891 | 1891 | </ul> |
| ... | ... | @@ -5392,7 +5392,7 @@ fn eql_i32(a: i32, b: i32) bool { |
| 5392 | 5392 | </p> |
| 5393 | 5393 | <p> |
| 5394 | 5394 | {#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this: |
| 5395 | | {#syntax#}pub const c_void = @OpaqueType();{#endsyntax#}. |
| 5395 | {#syntax#}pub const c_void = @Type(.Opaque);{#endsyntax#}. |
| 5396 | 5396 | {#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size. |
| 5397 | 5397 | </p> |
| 5398 | 5398 | <p> |
| ... | ... | @@ -7666,30 +7666,6 @@ mem.set(u8, dest, c);{#endsyntax#}</pre> |
| 7666 | 7666 | </p> |
| 7667 | 7667 | {#header_close#} |
| 7668 | 7668 | |
| 7669 | | {#header_open|@OpaqueType#} |
| 7670 | | <pre>{#syntax#}@OpaqueType() type{#endsyntax#}</pre> |
| 7671 | | <p> |
| 7672 | | Creates a new type with an unknown (but non-zero) size and alignment. |
| 7673 | | </p> |
| 7674 | | <p> |
| 7675 | | This is typically used for type safety when interacting with C code that does not expose struct details. |
| 7676 | | Example: |
| 7677 | | </p> |
| 7678 | | {#code_begin|test_err|expected type '*Derp', found '*Wat'#} |
| 7679 | | const Derp = @OpaqueType(); |
| 7680 | | const Wat = @OpaqueType(); |
| 7681 | | |
| 7682 | | extern fn bar(d: *Derp) void; |
| 7683 | | fn foo(w: *Wat) callconv(.C) void { |
| 7684 | | bar(w); |
| 7685 | | } |
| 7686 | | |
| 7687 | | test "call foo" { |
| 7688 | | foo(undefined); |
| 7689 | | } |
| 7690 | | {#code_end#} |
| 7691 | | {#header_close#} |
| 7692 | | |
| 7693 | 7669 | {#header_open|@panic#} |
| 7694 | 7670 | <pre>{#syntax#}@panic(message: []const u8) noreturn{#endsyntax#}</pre> |
| 7695 | 7671 | <p> |
| ... | ... | @@ -8274,21 +8250,21 @@ test "integer truncation" { |
| 8274 | 8250 | <li>{#syntax#}comptime_float{#endsyntax#}</li> |
| 8275 | 8251 | <li>{#syntax#}@TypeOf(undefined){#endsyntax#}</li> |
| 8276 | 8252 | <li>{#syntax#}@TypeOf(null){#endsyntax#}</li> |
| 8253 | <li>{#link|Arrays#}</li> |
| 8254 | <li>{#link|Optionals#}</li> |
| 8255 | <li>{#link|Error Union Type#}</li> |
| 8256 | <li>{#link|Vectors#}</li> |
| 8257 | <li>{#link|Opaque Types#}</li> |
| 8258 | <li>AnyFrame</li> |
| 8277 | 8259 | </ul> |
| 8278 | 8260 | <p> |
| 8279 | 8261 | For these types it is a |
| 8280 | 8262 | <a href="https://github.com/ziglang/zig/issues/2907">TODO in the compiler to implement</a>: |
| 8281 | 8263 | </p> |
| 8282 | 8264 | <ul> |
| 8283 | | <li>Array</li> |
| 8284 | | <li>Optional</li> |
| 8285 | | <li>ErrorUnion</li> |
| 8286 | 8265 | <li>ErrorSet</li> |
| 8287 | 8266 | <li>Enum</li> |
| 8288 | | <li>Opaque</li> |
| 8289 | 8267 | <li>FnFrame</li> |
| 8290 | | <li>AnyFrame</li> |
| 8291 | | <li>Vector</li> |
| 8292 | 8268 | <li>EnumLiteral</li> |
| 8293 | 8269 | </ul> |
| 8294 | 8270 | <p> |
| ... | ... | @@ -8373,6 +8349,28 @@ fn foo(comptime T: type, ptr: *T) T { |
| 8373 | 8349 | {#header_close#} |
| 8374 | 8350 | {#header_close#} |
| 8375 | 8351 | |
| 8352 | {#header_open|Opaque Types#} |
| 8353 | {#syntax#}@Type(.Opaque){#endsyntax#} creates a new type with an unknown (but non-zero) size and alignment. |
| 8354 | </p> |
| 8355 | <p> |
| 8356 | This is typically used for type safety when interacting with C code that does not expose struct details. |
| 8357 | Example: |
| 8358 | </p> |
| 8359 | {#code_begin|test_err|expected type '*Derp', found '*Wat'#} |
| 8360 | const Derp = @Type(.Opaque); |
| 8361 | const Wat = @Type(.Opaque); |
| 8362 | |
| 8363 | extern fn bar(d: *Derp) void; |
| 8364 | fn foo(w: *Wat) callconv(.C) void { |
| 8365 | bar(w); |
| 8366 | } |
| 8367 | |
| 8368 | test "call foo" { |
| 8369 | foo(undefined); |
| 8370 | } |
| 8371 | {#code_end#} |
| 8372 | {#header_close#} |
| 8373 | |
| 8376 | 8374 | {#header_open|Build Mode#} |
| 8377 | 8375 | <p> |
| 8378 | 8376 | Zig has four build modes: |