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: Fri, 2 May 2025 10:24:50 +0200
To put it in a different way: it is possible for the compiler to know what
a function pointer references, but not the actual pointer value. So == is
possible, <=> is not.

On Fri, May 2, 2025, 10:23 Robin Savonen Söderholm <
robinsavonensoderholm_at_[hidden]> wrote:

> No, you don't want to break ODR, and as such, each translation unit must
> agree on the values for each pointer. But that is just impossible at
> compile time, as it is essentially the linker that actually gives the
> addresses for the functions..
>
> // Robin
>
> On Fri, May 2, 2025, 10:20 Filip <fph2137_at_[hidden]> wrote:
>
>> 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:25:05