typing out the stuff on the website
parent
4ec36e3cf0
commit
28ebd12e92
@ -0,0 +1,4 @@
|
||||
test "integer overflow at compile time" {
|
||||
const x: u8 = 255;
|
||||
const y = x + 1;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
test "integer overflow at runtime" {
|
||||
var x: u8 = 255;
|
||||
x += 1;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
// if you remove this line, the program does not compile because it detects
|
||||
// the overflow at compile time. A little confusing that it's not
|
||||
// @setCompileTimeSafety but that's ok.
|
||||
@setRuntimeSafety(false);
|
||||
|
||||
var x: u8 = 255;
|
||||
x += 1; // <-- this is an overflow
|
||||
|
||||
// this prints 0 on my machine but is apparently undefined. I wonder what
|
||||
// it prints on other machines?
|
||||
std.debug.print("X: {}\n", .{x});
|
||||
}
|
Loading…
Reference in New Issue