#Why are pointer to different numbers the same?

1 messages · Page 1 of 1 (latest)

neon zinc
#

Code:

const std = @import("std");

test {
    const b = 1;
    const a = 10;
    try std.testing.expect(@intFromPtr(&a) != @intFromPtr(&b));
}

When I run the test.

Test [1/1] test_0... FAIL (TestUnexpectedResult)
/opt/homebrew/Cellar/zig/0.11.0/lib/zig/std/testing.zig:515:14: 0x1000007a3 in expect (test)
    if (!ok) return error.TestUnexpectedResult;
             ^
/Users/santiago.cabrera/dev/zig/computer-enhance/part3/src/demo.zig:6:5: 0x1000008f3 in test_0 (test)
    try std.testing.expect(@intFromPtr(&a) != @intFromPtr(&b));
    ^
0 passed; 0 skipped; 1 failed.

Why would the pointers to these two be the same?

wild crater
neon zinc
#

True, worked as expected by adding a type to them. Thanks