I actually did try (for a different thing, not this) compating two different poitners to the same global const declaration and I could not get them to be equal. But I spent like two minutes so I probably missed somehting.
That should work, the bug was elsewhere on that one (like you said, two minutes, no big deal).
Iām thinking about esoteric edge cases like merging two functions which end up with the same IR, but, it was more of an abstract question about what the language should allow than anything practical. Iām fairly sure, but not certain, that a function which doesnāt have any comptime specialization will compare equal by pointer as a matter of practice.
A single case doesnāt prove the rule but:
fn sillyFn(i: usize) !?usize {
if (i >= 5) return null;
return i + 1;
}
test "fn pointer equality" {
try expectEqual(&sillyFn, &sillyFn);
try expect(&sillyFn == &sillyFn);
}
In C this is something one can rely on, and plenty of code in the wild does. Zig is not (yet) specified so there are a lot of question marks about esoteric stuff like this.
By the way, what you canāt rely on, is that pointers to two different āglobalā const values will compare as different. Zig interns strings, so if they have different identifiers / namespaces, but the same value, their pointers will be equal. Another thing where it is not clear that the language will guarantee this, but it does happen to be the case.