stage2: implement coercion from null to C pointer

This commit is contained in:
Andrew Kelley
2021-10-17 19:10:49 -07:00
parent e5dac0a0b3
commit 40cbf525f7
4 changed files with 33 additions and 25 deletions

View File

@@ -44,3 +44,17 @@ test "double pointer parsing" {
fn PtrOf(comptime T: type) type {
return *T;
}
test "implicit cast single item pointer to C pointer and back" {
var y: u8 = 11;
var x: [*c]u8 = &y;
var z: *u8 = x;
z.* += 1;
try expect(y == 12);
}
test "initialize const optional C pointer to null" {
const a: ?[*c]i32 = null;
try expect(a == null);
comptime try expect(a == null);
}