Date: Sat, 26 Apr 2025 20:49:37 -0600
On Apr 26, 2025, at 11:34, Andrey Semashev via Std-Discussion <std-discussion_at_[hidden]> wrote:
>
>
> The point is, even if the standard guarantees this [pointers to different functions comparing unequal], it's probably not a
> good idea to rely on this in practice.
>
This being so, does anyone know if there has ever been a formal proposal to weaken this rule, or informal study of doing so?
I can certainly see the aesthetic argument for the rule, but I wonder how much real-life code actually relies on it. The only specific use case I can see is sentinels:
void sentinel() { }
void foo(void (*callback)()) {
if (!callback) {
proceed_without_callback();
} else if (callback == sentinel) {
something_special();
} else {
callback();
}
}
but it seems like a modern C++ programmer would rather do that with std::variant or some other way. So I wonder if anyone has studied the impact on existing code bases of dropping this guarantee.
>
>
> The point is, even if the standard guarantees this [pointers to different functions comparing unequal], it's probably not a
> good idea to rely on this in practice.
>
This being so, does anyone know if there has ever been a formal proposal to weaken this rule, or informal study of doing so?
I can certainly see the aesthetic argument for the rule, but I wonder how much real-life code actually relies on it. The only specific use case I can see is sentinels:
void sentinel() { }
void foo(void (*callback)()) {
if (!callback) {
proceed_without_callback();
} else if (callback == sentinel) {
something_special();
} else {
callback();
}
}
but it seems like a modern C++ programmer would rather do that with std::variant or some other way. So I wonder if anyone has studied the impact on existing code bases of dropping this guarantee.
Received on 2025-04-27 02:49:51