C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Guarantees over addresses from function pointers created from lambda

From: Filip <fph2137_at_[hidden]>
Date: Fri, 2 May 2025 10:20:29 +0200
Maybe a stupid question but aren’t pointers just numbers and as such should be comparable?

And during compilation wouldn’t it basically always be the order of compilation of this functions that is being tested by < ?

Cheers, Filip

Wiadomość napisana przez Robin Savonen Söderholm via Std-Proposals <std-proposals_at_[hidden]> w dniu 30 kwi 2025, o godz. 20:00:


Hmm yes.. The operator< is not allowed to be used in constant expressions for function pointers it seems.

// Robin

On Wed, Apr 30, 2025 at 7:47 PM Thiago Macieira <thiago_at_[hidden]> wrote:
On Wednesday, 30 April 2025 10:42:55 Pacific Daylight Time Robin Savonen
Söderholm wrote:
> I'm curious with this compile-time/runtime representation difference. We can
> sort things in compile time. If I make a sorted compile-time array of
> function pointers (sorted by the regular "ptr < ptr" sense) and then in
> runtime do a binary search to check if a certain function exists in that
> array, would that be well-defined behaviour, and how?

You can only order pointers that belong to the same array. Anything else is
UB. That would include trying to see if &i < &j for two namespace-scope
integer variables and definitely two functions.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering



--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-05-02 08:20:45