C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Well-defined behaviour and implicit conversion for function pointers that take void*

From: Magnus Fromreide <magfr_at_[hidden]>
Date: Fri, 8 Jul 2022 15:44:25 +0200
On Fri, Jul 08, 2022 at 11:53:42AM +0100, Frederick Virchanza Gotham via Std-Proposals wrote:
> Let's say we have two functions as follows:
>
> class Alpha;
> class Beta ;
>
> void Configure_Alpha(Alpha*);
> void Configure_Beta (Beta *);
>
> I propose that we should be able to use the following function pointer:
>
> void (*Configure)(void*);
>
> to store the address of either of the two functions (without the need
> for a cast), and for the behaviour to be well-defined if we then use
> 'Configure' to make a function call. In terms of CPU architecture and
> assembler, there is only one pre-requisite here for this to work
> properly:
>
> sizeof(void*) == sizeof(Alpha*) == sizeof(Beta*)
>

Is this precondition really true even on your platform?

What about function pointers?

What about member pointers?

I did suggest something similar back in
2014 ( https://groups.google.com/a/isocpp.org/g/std-proposals/c/9hXHc6AS9M8/m/UaNJs0nZgQQJ ) but
it went down in flames.

/MF

Received on 2022-07-08 13:44:29