C++ Logo

std-proposals

Advanced search

Re: [std-proposals] "shared libraries are outside the scope of the C++ standard"

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 13 Jul 2023 09:00:09 -0700
On Thursday, 13 July 2023 00:10:46 PDT Ofek Shilon via Std-Proposals wrote:
> The problematic situation is code like:
>
> // executable:
> void ImplementedInLibA();
> bool compareFuncPtrsInLibB(void (*)());
>
> int main {
> void (*pf1)() = &ImplementedInLibA();
> compareFuncPtrsInLibB(pf1);
> }
>
> // shared lib B:
> bool compareFuncPtrsInLibB(void (*pf)()) {
> void (*pf2)() = &ImplementedInLibA();
> return pf == pf2; // true on Linux, false on Windows
> }

It needs to be more complex than this. As I said in my reply, this only
applies to pointers stored to read-only memory.

The code above (with the necessary fixes) prints "Compare equal" with both
VS2022 and GCC 13. See https://msvc.godbolt.org/z/snPe7cGWq.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-07-13 16:00:12