C++ Logo

std-proposals

Advanced search

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

From: Robin Savonen Söderholm <robinsavonensoderholm_at_[hidden]>
Date: Wed, 30 Apr 2025 20:00:11 +0200
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
>
>
>
>

Received on 2025-04-30 18:00:22