Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.c++ / Proper cast of function pointers

SubjectAuthor
* Proper cast of function pointersPaavo Helde
+* Re: Proper cast of function pointersBonita Montero
|`* Re: Proper cast of function pointersPaavo Helde
| +- Re: Proper cast of function pointersDavid Brown
| +* Re: Proper cast of function pointersBonita Montero
| |`* Re: Proper cast of function pointersPaavo Helde
| | +* Re: Proper cast of function pointersTim Rentsch
| | |+- Re: Proper cast of function pointersChris M. Thomasson
| | |`* Re: Proper cast of function pointersPaavo Helde
| | | `- Re: Proper cast of function pointersTim Rentsch
| | `* Re: Proper cast of function pointersBonita Montero
| |  `* Re: Proper cast of function pointersBonita Montero
| |   `* Re: Proper cast of function pointersBonita Montero
| |    `* Re: Proper cast of function pointersPaavo Helde
| |     `- Re: Proper cast of function pointersBonita Montero
| `- Re: Proper cast of function pointersTim Rentsch
+* Re: Proper cast of function pointersMarkus Schaaf
|+* Re: Proper cast of function pointersDavid Brown
||+* Re: Proper cast of function pointersMarkus Schaaf
|||+- Re: Proper cast of function pointersDavid Brown
|||`* Re: Proper cast of function pointersBonita Montero
||| `- Re: Proper cast of function pointersDavid Brown
||`* Re: Proper cast of function pointersBonita Montero
|| `* Re: Proper cast of function pointersDavid Brown
||  `* Re: Proper cast of function pointersBonita Montero
||   `* Re: Proper cast of function pointersDavid Brown
||    `- Re: Proper cast of function pointersBonita Montero
|`* Re: Proper cast of function pointersPaavo Helde
| `* Re: Proper cast of function pointersMarkus Schaaf
|  +- Re: Proper cast of function pointersMarkus Schaaf
|  `- Re: Proper cast of function pointersPaavo Helde
`* Re: Proper cast of function pointersDavid Brown
 `* Re: Proper cast of function pointersBonita Montero
  `* Re: Proper cast of function pointersDavid Brown
   +* Re: Proper cast of function pointersBo Persson
   |`- Re: Proper cast of function pointersDavid Brown
   `* Re: Proper cast of function pointersBonita Montero
    `* Re: Proper cast of function pointersDavid Brown
     `* Re: Proper cast of function pointersBonita Montero
      `* Re: Proper cast of function pointersDavid Brown
       `- Re: Proper cast of function pointersBonita Montero

Pages:12
Proper cast of function pointers

<v08672$1jh9c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3667&group=comp.lang.c%2B%2B#3667

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Proper cast of function pointers
Date: Tue, 23 Apr 2024 14:31:43 +0300
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <v08672$1jh9c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 23 Apr 2024 13:31:46 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8cd16bea83eb660446987f3941b0ed94";
logging-data="1688876"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bY3IuQ1H3W2uNd/wA6f3wROnmcyyV6Y8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:J/N6liQ04q76pERLKWPWm7QV/J4=
Content-Language: en-US
 by: Paavo Helde - Tue, 23 Apr 2024 11:31 UTC

There is an old third-party library where some function pointers are
casted to another type, then back to the original type before use. C++
standard says this is kosher, and there have never been any problems
with actual behavior. Alas, different versions and compile modes of g++
still produce warnings. What would be the best way to silence them
(without just switching off warnings)?

Simplified example:

typedef double (*Func)(double);
typedef double (*DoubleFunc_2_args)(double, double);

Func FuncCast2(DoubleFunc_2_args fp) {
return reinterpret_cast<Func>(fp);
}

$ g++ test1.cpp -Wall -Wextra
test1.cpp: In function ‘double (* FuncCast2(DoubleFunc_2_args))(double)’:
test1.cpp:26:34: warning: cast between incompatible function types from
‘DoubleFunc_2_args’ {aka ‘double (*)(double, double)’} to ‘Func’ {aka
‘double (*)(double)’} [-Wcast-function-type]
return reinterpret_cast<Func>(fp);

If I change the function to use more indirection, then there is a
warning with -O2 only:

Func FuncCast2(DoubleFunc_2_args fp) {
return *reinterpret_cast<Func*>(&fp);
}

$ g++ test1.cpp -Wall -Wextra -O2
test1.cpp: In function ‘double (* FuncCast2(DoubleFunc_2_args))(double)’:
test1.cpp:22:10: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
return *reinterpret_cast<Func*>(&fp);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~

$ g++ --version
g++ (Debian 10.2.1-6) 10.2.1 20210110

Re: Proper cast of function pointers

<v086ut$1jkn4$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3668&group=comp.lang.c%2B%2B#3668

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 13:44:30 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <v086ut$1jkn4$1@raubtier-asyl.eternal-september.org>
References: <v08672$1jh9c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Apr 2024 13:44:30 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="70734427025ac6155b044ec072dc2533";
logging-data="1692388"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SPo/um1Q+5oVIuXGSNQMjG3g8WuReD7M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CeVXPr4tln2XtuJ1vcrgTVHm3b4=
In-Reply-To: <v08672$1jh9c$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Tue, 23 Apr 2024 11:44 UTC

Am 23.04.2024 um 13:31 schrieb Paavo Helde:
>
> There is an old third-party library where some function pointers are
> casted to another type, then back to the original type before use.
> C++ standard says this is kosher, and there have never been any
> problems with actual behavior. Alas, different versions and compile
> modes of g++ still produce warnings. ...

That's because of the danger that someone calls the function-pointer
to which you cast. Maybe you can cast through a void-pointer to sup-
press this warning. But for me casting to a function pointer of a
differnt type doesn't make sense at at..
I think you confront yourself to uncertainties which actually never
happen.

Re: Proper cast of function pointers

<v08985$1j0ue$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3669&group=comp.lang.c%2B%2B#3669

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: msch...@elaboris.de (Markus Schaaf)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 14:23:33 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v08985$1j0ue$3@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 23 Apr 2024 14:23:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e34f93e52e4638132acb3096675d0860";
logging-data="1672142"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+AcFa8X3Yio9VeqJmfV0r"
User-Agent: Mozilla Thunderbird
In-Reply-To: <v08672$1jh9c$1@dont-email.me>
Content-Language: de-DE, en-US
 by: Markus Schaaf - Tue, 23 Apr 2024 12:23 UTC

Am 23.04.24 um 13:31 schrieb Paavo Helde:
>
> There is an old third-party library where some function pointers are
> casted to another type, then back to the original type before use. C++
> standard says this is kosher, and there have never been any problems
> with actual behavior. Alas, different versions and compile modes of g++
> still produce warnings. What would be the best way to silence them
> (without just switching off warnings)?

You could use a union, if you know all possible function types
beforehand.

> typedef double (*Func)(double);
> typedef double (*DoubleFunc_2_args)(double, double);
>
> Func FuncCast2(DoubleFunc_2_args fp) {
> return reinterpret_cast<Func>(fp);
> }
>
> $ g++ test1.cpp -Wall -Wextra
> test1.cpp: In function ‘double (* FuncCast2(DoubleFunc_2_args))(double)’:
> test1.cpp:26:34: warning: cast between incompatible function types from
> ‘DoubleFunc_2_args’ {aka ‘double (*)(double, double)’} to ‘Func’ {aka
> ‘double (*)(double)’} [-Wcast-function-type]
> return reinterpret_cast<Func>(fp);

You could wonder why you are asking for non-standard (extra)
warnings in the first place.

Out of curiosity I have fiddled with g++, asking myself if there
is a type like (void*) for objects, that the compiler is happy
converting function pointers into. And alas, there is! And it is
the type one would guess:

typedef void (*UniversalFunctionPointer)();

Of course it's a cat-and-mouse play with these compiler warnings.

BR

Re: Proper cast of function pointers

<v08hg0$1m0ss$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3670&group=comp.lang.c%2B%2B#3670

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 16:44:16 +0200
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <v08hg0$1m0ss$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 23 Apr 2024 16:44:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ad8e0339bf198d7ad938e7682bda7aff";
logging-data="1770396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GvWS94IsQi80u6XvlrCNrwvxEATzAoYo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:pniO7nByJjC49l5gQA6zYSnKcDw=
Content-Language: en-GB
In-Reply-To: <v08672$1jh9c$1@dont-email.me>
 by: David Brown - Tue, 23 Apr 2024 14:44 UTC

On 23/04/2024 13:31, Paavo Helde wrote:
>
> There is an old third-party library where some function pointers are
> casted to another type, then back to the original type before use. C++
> standard says this is kosher, and there have never been any problems
> with actual behavior. Alas, different versions and compile modes of g++
> still produce warnings. What would be the best way to silence them
> (without just switching off warnings)?
>
>
> Simplified example:
>
> typedef double (*Func)(double);
> typedef double (*DoubleFunc_2_args)(double, double);
>
> Func FuncCast2(DoubleFunc_2_args fp) {
>     return reinterpret_cast<Func>(fp);
> }
>
> $ g++ test1.cpp -Wall -Wextra
> test1.cpp: In function ‘double (* FuncCast2(DoubleFunc_2_args))(double)’:
> test1.cpp:26:34: warning: cast between incompatible function types from
> ‘DoubleFunc_2_args’ {aka ‘double (*)(double, double)’} to ‘Func’ {aka
> ‘double (*)(double)’} [-Wcast-function-type]
>   return reinterpret_cast<Func>(fp);
>
>
> If I change the function to use more indirection, then there is a
> warning with -O2 only:
>
> Func FuncCast2(DoubleFunc_2_args fp) {
>     return *reinterpret_cast<Func*>(&fp);
> }
>
> $ g++ test1.cpp -Wall -Wextra -O2
> test1.cpp: In function ‘double (* FuncCast2(DoubleFunc_2_args))(double)’:
> test1.cpp:22:10: warning: dereferencing type-punned pointer will break
> strict-aliasing rules [-Wstrict-aliasing]
>   return *reinterpret_cast<Func*>(&fp);
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> $ g++ --version
> g++ (Debian 10.2.1-6) 10.2.1 20210110

The compiler is warning here about casting incompatible function types
because usually such casts are a bad idea. In particular, casting to a
different function type, then calling through this new type, is
undefined behaviour. About the only useful thing you can do with your
cast pointer is cast it back to the original type before calling it. So
g++ with -Wextra warns you that you have either made a mistake in your
code, or are trying to do something that is potentially dangerous.

The compiler then helpfully tells you exactly why you got the warning,
and makes it obvious what you can do to hide the warning, by giving you
the specific flag - "-Wcast-function-type". You disable that warning by
using "-Wno-cast-function-type", or by using the appropriate pragma:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
inline Func FuncCast2(DoubleFunc_2_args fp) {
return reinterpret_cast<Func>(fp);
} #pragma GCC diagnostic pop

Re: Proper cast of function pointers

<v08hg4$1m0ss$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3671&group=comp.lang.c%2B%2B#3671

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 16:44:20 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <v08hg4$1m0ss$2@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 23 Apr 2024 16:44:21 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ad8e0339bf198d7ad938e7682bda7aff";
logging-data="1770396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bwelIsBb9FbVlqqf320eek0d6nbv40N0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:j44rXos63E3Vzu6OvC6WPuNN8/A=
In-Reply-To: <v08985$1j0ue$3@dont-email.me>
Content-Language: en-GB
 by: David Brown - Tue, 23 Apr 2024 14:44 UTC

On 23/04/2024 14:23, Markus Schaaf wrote:
> Am 23.04.24 um 13:31 schrieb Paavo Helde:
>>
>> There is an old third-party library where some function pointers are
>> casted to another type, then back to the original type before use. C++
>> standard says this is kosher, and there have never been any problems
>> with actual behavior. Alas, different versions and compile modes of g++
>> still produce warnings. What would be the best way to silence them
>> (without just switching off warnings)?
>
> You could use a union, if you know all possible function types beforehand.
>

You /could/, if you don't mind the undefined behaviour - type-punning
unions are not defined behaviour in C++.

>> typedef double (*Func)(double);
>> typedef double (*DoubleFunc_2_args)(double, double);
>>
>> Func FuncCast2(DoubleFunc_2_args fp) {
>>     return reinterpret_cast<Func>(fp);
>> }
>>
>> $ g++ test1.cpp -Wall -Wextra
>> test1.cpp: In function ‘double (* FuncCast2(DoubleFunc_2_args))(double)’:
>> test1.cpp:26:34: warning: cast between incompatible function types from
>> ‘DoubleFunc_2_args’ {aka ‘double (*)(double, double)’} to ‘Func’ {aka
>> ‘double (*)(double)’} [-Wcast-function-type]
>>     return reinterpret_cast<Func>(fp);
>
> You could wonder why you are asking for non-standard (extra) warnings in
> the first place.
>

I can't answer for the OP, but I know why /I/ use lots of extra warnings
in my code. (What do you mean by "non-standard warnings" anyway? There
are standards-required diagnostics, but AFAIK the standard does not
distinguish between errors and warnings, except for #error directives.)

Re: Proper cast of function pointers

<v08ien$1ke8k$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3672&group=comp.lang.c%2B%2B#3672

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: msch...@elaboris.de (Markus Schaaf)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 17:00:39 +0200
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <v08ien$1ke8k$2@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08hg4$1m0ss$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Apr 2024 17:00:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e34f93e52e4638132acb3096675d0860";
logging-data="1718548"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18H8XXilA0ZV68qsyYVT1zV"
User-Agent: Mozilla Thunderbird
In-Reply-To: <v08hg4$1m0ss$2@dont-email.me>
Content-Language: de-DE, en-US
 by: Markus Schaaf - Tue, 23 Apr 2024 15:00 UTC

Am 23.04.24 um 16:44 schrieb David Brown:
> On 23/04/2024 14:23, Markus Schaaf wrote:
>> Am 23.04.24 um 13:31 schrieb Paavo Helde:
>>>
>>> There is an old third-party library where some function pointers are
>>> casted to another type, then back to the original type before use. C++
>>> standard says this is kosher, and there have never been any problems
>>> with actual behavior. Alas, different versions and compile modes of g++
>>> still produce warnings. What would be the best way to silence them
>>> (without just switching off warnings)?
>>
>> You could use a union, if you know all possible function types beforehand.
>>
>
> You /could/, if you don't mind the undefined behaviour - type-punning
> unions are not defined behaviour in C++.

I have no idea what you are writing about. Of course one would
read the exact same member of the union one had written to
before. That is what unions are for.

BR

Re: Proper cast of function pointers

<v08ut6$1p6m1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3675&group=comp.lang.c%2B%2B#3675

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 21:33:10 +0300
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <v08ut6$1p6m1$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me>
<v086ut$1jkn4$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 23 Apr 2024 20:33:10 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="615254b34bbc61db2ea5190389649948";
logging-data="1874625"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iD9GU/5WRxcfX8+Yj58IQ7zTS18suhzg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CDWFDjLlQnx1aNXrRI8oO7eYbe4=
Content-Language: en-US
In-Reply-To: <v086ut$1jkn4$1@raubtier-asyl.eternal-september.org>
 by: Paavo Helde - Tue, 23 Apr 2024 18:33 UTC

23.04.2024 14:44 Bonita Montero kirjutas:
> Am 23.04.2024 um 13:31 schrieb Paavo Helde:
>>
>> There is an old third-party library where some function pointers are
>> casted to another type, then back to the original type before use.
>> C++  standard says this is kosher, and there have never been any
>> problems  with actual behavior. Alas, different versions and compile
>> modes of g++ still produce warnings. ...
>
> That's because of the danger that someone calls the function-pointer
> to which you cast. Maybe you can cast through a void-pointer to sup-
> press this warning. But for me casting to a function pointer of a
> differnt type doesn't make sense at at..
> I think you confront yourself to uncertainties which actually never
> happen.
>

The function pointers are cast to a single type so that they can be
stored in a common lookup array. I could use a union there, but this
would mean additional work with no real benefit, as the hypothetical
"someone" could just as easily mess up the unions than the casting.

Re: Proper cast of function pointers

<v08vu5$1perd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3676&group=comp.lang.c%2B%2B#3676

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 21:50:44 +0300
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <v08vu5$1perd$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 23 Apr 2024 20:50:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8cd16bea83eb660446987f3941b0ed94";
logging-data="1882989"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/U8yxO8pb6TRn/g5ixgxw3F4ZCa+dfC4s="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:G4NO7+mFgUAlBPzB28t3xa6KdBo=
In-Reply-To: <v08985$1j0ue$3@dont-email.me>
Content-Language: en-US
 by: Paavo Helde - Tue, 23 Apr 2024 18:50 UTC

23.04.2024 15:23 Markus Schaaf kirjutas:
> Am 23.04.24 um 13:31 schrieb Paavo Helde:
>>
>> There is an old third-party library where some function pointers are
>> casted to another type, then back to the original type before use. C++
>> standard says this is kosher, and there have never been any problems
>> with actual behavior. Alas, different versions and compile modes of g++
>> still produce warnings. What would be the best way to silence them
>> (without just switching off warnings)?
>
> You could use a union, if you know all possible function types beforehand.

Right, I could use union, it's just extra work and some danger of
introducing new bugs in this old third-party code.

>
>> typedef double (*Func)(double);
>> typedef double (*DoubleFunc_2_args)(double, double);
>>
>> Func FuncCast2(DoubleFunc_2_args fp) {
>>     return reinterpret_cast<Func>(fp);
>> }
>>
>> $ g++ test1.cpp -Wall -Wextra
>> test1.cpp: In function ‘double (* FuncCast2(DoubleFunc_2_args))(double)’:
>> test1.cpp:26:34: warning: cast between incompatible function types from
>> ‘DoubleFunc_2_args’ {aka ‘double (*)(double, double)’} to ‘Func’ {aka
>> ‘double (*)(double)’} [-Wcast-function-type]
>>     return reinterpret_cast<Func>(fp);
>
> You could wonder why you are asking for non-standard (extra) warnings in
> the first place.

Because using -Wall -Wextra (and sometimes more) has been encouraged by
people in this group and elsewhere.

I suspect -Wcast-function-type has been added into -Wextra during some
last 10 years, I'm pretty sure earlier this code used to compile without
warnings, it has been relatively recently when this has started to
irritate me (mostly because we have managed to get the rest of the
codebase almost warning-free ;-).

>
> Out of curiosity I have fiddled with g++, asking myself if there is a
> type like (void*) for objects, that the compiler is happy converting
> function pointers into. And alas, there is! And it is the type one would
> guess:
>
> typedef void (*UniversalFunctionPointer)();

Adding an intermediate reinterpret_cast to this type indeed seems to get
rid of the warning! Thanks a lot!

Re: Proper cast of function pointers

<v09539$1q6l1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3677&group=comp.lang.c%2B%2B#3677

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: msch...@elaboris.de (Markus Schaaf)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 22:18:49 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <v09539$1q6l1$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08vu5$1perd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Apr 2024 22:18:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="03dfa523d80e76acf6b5e84c43f33613";
logging-data="1907361"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198qN5E5d9xXIP6SzggEtX0"
User-Agent: Mozilla Thunderbird
Content-Language: de-DE, en-US
In-Reply-To: <v08vu5$1perd$1@dont-email.me>
 by: Markus Schaaf - Tue, 23 Apr 2024 20:18 UTC

Am 23.04.24 um 20:50 schrieb Paavo Helde:

>> typedef void (*UniversalFunctionPointer)();
>
> Adding an intermediate reinterpret_cast to this type indeed seems to get
> rid of the warning! Thanks a lot!

Wouldn't it be better to change the storage type of these
function pointers in your registry to above type, making the
intention clear to those you recognize its special property?
Instead of introducing obscure cast chains everywhere.

BR

Re: Proper cast of function pointers

<v095a5$1q6l1$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3678&group=comp.lang.c%2B%2B#3678

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: msch...@elaboris.de (Markus Schaaf)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 22:22:29 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <v095a5$1q6l1$2@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08vu5$1perd$1@dont-email.me> <v09539$1q6l1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Apr 2024 22:22:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="03dfa523d80e76acf6b5e84c43f33613";
logging-data="1907361"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197/uM+4bomgC+I0AcJJwh5"
User-Agent: Mozilla Thunderbird
In-Reply-To: <v09539$1q6l1$1@dont-email.me>
Content-Language: de-DE, en-US
 by: Markus Schaaf - Tue, 23 Apr 2024 20:22 UTC

Am 23.04.24 um 22:18 schrieb Markus Schaaf:

> intention clear to those you recognize its special property?

.... to those who recognize ...

(Phonetic typing error, interesting.)

BR

Re: Proper cast of function pointers

<v095ur$1qvj8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3679&group=comp.lang.c%2B%2B#3679

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Tue, 23 Apr 2024 23:33:30 +0300
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <v095ur$1qvj8$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08vu5$1perd$1@dont-email.me> <v09539$1q6l1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Apr 2024 22:33:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8cd16bea83eb660446987f3941b0ed94";
logging-data="1932904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IH+DHU0uqA7I+Zez6FEaAOiXu1Bxv/50="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yBVGMR+dL404dAgFA5aNIKn8elE=
Content-Language: en-US
In-Reply-To: <v09539$1q6l1$1@dont-email.me>
 by: Paavo Helde - Tue, 23 Apr 2024 20:33 UTC

23.04.2024 23:18 Markus Schaaf kirjutas:
> Am 23.04.24 um 20:50 schrieb Paavo Helde:
>
>>> typedef void (*UniversalFunctionPointer)();
>>
>> Adding an intermediate reinterpret_cast to this type indeed seems to get
>> rid of the warning! Thanks a lot!
>
> Wouldn't it be better to change the storage type of these function
> pointers in your registry to above type, making the intention clear to
> those you recognize its special property? Instead of introducing obscure
> cast chains everywhere.

Yes, it would be better or at least more symmetric, assuming that
somebody will read this third-party code some day. This has not happened
in the last 20 years, but you never know. I will think about that.

BR

Re: Proper cast of function pointers

<v0acjo$26ofk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3684&group=comp.lang.c%2B%2B#3684

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 09:33:12 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <v0acjo$26ofk$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me>
<v086ut$1jkn4$1@raubtier-asyl.eternal-september.org>
<v08ut6$1p6m1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 24 Apr 2024 09:33:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e52005174aa1993ff22f62609fe4959";
logging-data="2318836"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/r+pt/qwDqO/Fssdyc3Ci6hZEf8iYm1Ew="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:tR0Z2VDsumb3e1ljv2gqKQHB1ZM=
In-Reply-To: <v08ut6$1p6m1$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 24 Apr 2024 07:33 UTC

On 23/04/2024 20:33, Paavo Helde wrote:
> 23.04.2024 14:44 Bonita Montero kirjutas:
>> Am 23.04.2024 um 13:31 schrieb Paavo Helde:
>>>
>>> There is an old third-party library where some function pointers are
>>> casted to another type, then back to the original type before use.
>>> C++  standard says this is kosher, and there have never been any
>>> problems  with actual behavior. Alas, different versions and compile
>>> modes of g++ still produce warnings. ...
>>
>> That's because of the danger that someone calls the function-pointer
>> to which you cast. Maybe you can cast through a void-pointer to sup-
>> press this warning. But for me casting to a function pointer of a
>> differnt type doesn't make sense at at..
>> I think you confront yourself to uncertainties which actually never
>> happen.
>>
>
> The function pointers are cast to a single type so that they can be
> stored in a common lookup array. I could use a union there, but this
> would mean additional work with no real benefit, as the hypothetical
> "someone" could just as easily mess up the unions than the casting.

You could consider using std::variant<>, but you need to know the
possible function types in advance (that may or may not be an issue for
you) and it stores an index to in the variant object. Again, that may
or may not be a useful thing for you.

Otherwise I agree with you that casting to a common "void (*)(void)"
pointer type seems reasonable here. Just disable the warning around the
casts.

Re: Proper cast of function pointers

<v0acqb$26rt3$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3685&group=comp.lang.c%2B%2B#3685

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 09:36:45 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <v0acqb$26rt3$1@raubtier-asyl.eternal-september.org>
References: <v08672$1jh9c$1@dont-email.me>
<v086ut$1jkn4$1@raubtier-asyl.eternal-september.org>
<v08ut6$1p6m1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 09:36:43 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="8489b4849e5ffcd9346751255d4a40b6";
logging-data="2322339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/v/z+7WrZ7AgWfJZyVzeIfa7jI/FzRUGc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5CoVILIMJsxP9gDQwEmWHf6W8h8=
In-Reply-To: <v08ut6$1p6m1$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 24 Apr 2024 07:36 UTC

Am 23.04.2024 um 20:33 schrieb Paavo Helde:

> The function pointers are cast to a single type so that they can be
> stored in a common lookup array. ...

Then you'd need additional information to distinguish the different
types. If you have sth. like that you could take a variant<>.

Re: Proper cast of function pointers

<v0adto$273oo$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3686&group=comp.lang.c%2B%2B#3686

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 09:55:36 +0200
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <v0adto$273oo$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08hg4$1m0ss$2@dont-email.me> <v08ien$1ke8k$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 09:55:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e52005174aa1993ff22f62609fe4959";
logging-data="2330392"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FW1xpFIjwfnwQ7467PgTDMGKjgLSkkFw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Mmc87bHPU/1icuyCatxqSogud4I=
Content-Language: en-GB
In-Reply-To: <v08ien$1ke8k$2@dont-email.me>
 by: David Brown - Wed, 24 Apr 2024 07:55 UTC

On 23/04/2024 17:00, Markus Schaaf wrote:
> Am 23.04.24 um 16:44 schrieb David Brown:
>> On 23/04/2024 14:23, Markus Schaaf wrote:
>>> Am 23.04.24 um 13:31 schrieb Paavo Helde:
>>>>
>>>> There is an old third-party library where some function pointers are
>>>> casted to another type, then back to the original type before use. C++
>>>> standard says this is kosher, and there have never been any problems
>>>> with actual behavior. Alas, different versions and compile modes of g++
>>>> still produce warnings. What would be the best way to silence them
>>>> (without just switching off warnings)?
>>>
>>> You could use a union, if you know all possible function types
>>> beforehand.
>>>
>>
>> You /could/, if you don't mind the undefined behaviour - type-punning
>> unions are not defined behaviour in C++.
>
> I have no idea what you are writing about. Of course one would read the
> exact same member of the union one had written to before. That is what
> unions are for.
>
> BR

Type-punning unions are defined behaviour in C, undefined in C++. A
typical example (written to be compilable as C and C++) would be :

typedef union RawFloat {
float f;
unsigned int u;
} RawFloat;

unsigned int float_to_raw(float f) {
RawFloat r;
r.f = f;
return r.u;
}

In C, writing to one union member and then reading via a different union
member is defined behaviour - you get the same underlying
representation, re-interpreted as the new type. This is known as "type
punning", and was explicitly given defined behaviour in C99. (Prior to
C99, the standard was vague on the topic.)

In C++, this is undefined behaviour - you may not read a union member
that was not the last written member.

Many - perhaps most - C++ compilers allow type-punning via unions in
C++, as long as they are standard layout unions (simple types with no
constructors, virtual functions, or anything beyond plain C). But this
is not defined behaviour according to the C++ standards. In C++, the
defined ways to achieve type punning are std::memcpy and std::bit_cast<>
(in C++20).

Unions were /not/ intended for type-punning. They were designed for
saving memory and to support "sum" types (compared to structs which are
"product" types). But they are also sometimes used for type-punning,
and the definition of this behaviour was added to C99 because some
people non-portably relied on that behaviour in existing C code. It was
/not/ added to C++ because specifying such a rule would be complicated
in the face of more advanced types.

<https://en.cppreference.com/w/c/language/union>
(See the first "since C99" box)

<https://en.cppreference.com/w/cpp/language/union>
(See the first paragraph of "Explanation")

Re: Proper cast of function pointers

<v0aj9s$28868$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3687&group=comp.lang.c%2B%2B#3687

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 11:27:26 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <v0aj9s$28868$1@raubtier-asyl.eternal-september.org>
References: <v08672$1jh9c$1@dont-email.me> <v08hg0$1m0ss$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 24 Apr 2024 11:27:24 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="8489b4849e5ffcd9346751255d4a40b6";
logging-data="2367688"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/K3RvmrbXgZKwv06YODXxP/B+LKpT1sUY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Rj2YbfXLnCGkdHmVoEY+kZIuipY=
In-Reply-To: <v08hg0$1m0ss$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 24 Apr 2024 09:27 UTC

Am 23.04.2024 um 16:44 schrieb David Brown:

> The compiler is warning here about casting incompatible function types
> because usually such casts are a bad idea.  In particular, casting to
> a different function type, then calling through this new type, is
> undefined behaviour.  About the only useful thing you can do with your
> cast pointer is cast it back to the original type before calling it.
> So g++ with -Wextra warns you that you have either made a mistake in
> your code, or are trying to do something that is potentially dangerous.

He needs to store different function-pointers with a common type;
why not as a void-pointer ?

Re: Proper cast of function pointers

<v0apan$29jei$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3688&group=comp.lang.c%2B%2B#3688

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 13:10:17 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <v0apan$29jei$1@raubtier-asyl.eternal-september.org>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08hg4$1m0ss$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 13:10:15 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="8489b4849e5ffcd9346751255d4a40b6";
logging-data="2411986"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RStw7EGo+phEP6dzGuq+880dopgUDAjI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:IZi7trBjrwHeXoNfQqMBGyxLdfg=
Content-Language: de-DE
In-Reply-To: <v08hg4$1m0ss$2@dont-email.me>
 by: Bonita Montero - Wed, 24 Apr 2024 11:10 UTC

Am 23.04.2024 um 16:44 schrieb David Brown:

> You /could/, if you don't mind the undefined behaviour - type-punning
> unions are not defined behaviour in C++.

Actually all compiler support that. But MSVC++ isn't that efficient
with that like clang or g++; MSVC often does a store and load round-
trip. But there's bit_cast with C++20, which also works efficient
with MSVC++. But actually he neither needs bit_cast nor unions for
his purpose, but just a reinterpret_cast or a C-style cast, which
I prefer for readability.

Re: Proper cast of function pointers

<v0apca$29jei$2@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3689&group=comp.lang.c%2B%2B#3689

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 13:11:08 +0200
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <v0apca$29jei$2@raubtier-asyl.eternal-september.org>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08hg4$1m0ss$2@dont-email.me> <v08ien$1ke8k$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 13:11:06 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="8489b4849e5ffcd9346751255d4a40b6";
logging-data="2411986"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QNAFXkorrhPwCnY+54dpRA/R1Wg4I09w="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:NtDCpu0UB9El7P5PgyCy+RyUVoU=
In-Reply-To: <v08ien$1ke8k$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 24 Apr 2024 11:11 UTC

Am 23.04.2024 um 17:00 schrieb Markus Schaaf:
> Am 23.04.24 um 16:44 schrieb David Brown:
>> On 23/04/2024 14:23, Markus Schaaf wrote:
>>> Am 23.04.24 um 13:31 schrieb Paavo Helde:
>>>>
>>>> There is an old third-party library where some function pointers are
>>>> casted to another type, then back to the original type before use. C++
>>>> standard says this is kosher, and there have never been any problems
>>>> with actual behavior. Alas, different versions and compile modes of g++
>>>> still produce warnings. What would be the best way to silence them
>>>> (without just switching off warnings)?
>>>
>>> You could use a union, if you know all possible function types
>>> beforehand.
>>>
>>
>> You /could/, if you don't mind the undefined behaviour - type-punning
>> unions are not defined behaviour in C++.
>
> I have no idea what you are writing about. Of course one would read the
> exact same member of the union one had written to before. That is what
> unions are for.

A union actually isn't needed for the discusses purpose.
Just do a reinterpret_cast or a C-style cast.

Re: Proper cast of function pointers

<v0apih$29msl$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3690&group=comp.lang.c%2B%2B#3690

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 13:14:24 +0200
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <v0apih$29msl$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08hg0$1m0ss$1@dont-email.me>
<v0aj9s$28868$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 24 Apr 2024 13:14:25 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e52005174aa1993ff22f62609fe4959";
logging-data="2415509"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19F3Bh2BJWx+dyM+hnXPgDzQuqu9t4wySU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:NDbgXv11xdroVGx3YzNjB5Nrblk=
In-Reply-To: <v0aj9s$28868$1@raubtier-asyl.eternal-september.org>
Content-Language: en-GB
 by: David Brown - Wed, 24 Apr 2024 11:14 UTC

On 24/04/2024 11:27, Bonita Montero wrote:
> Am 23.04.2024 um 16:44 schrieb David Brown:
>
>> The compiler is warning here about casting incompatible function types
>> because usually such casts are a bad idea.  In particular, casting to
>> a  different function type, then calling through this new type, is
>> undefined behaviour.  About the only useful thing you can do with your
>> cast pointer is cast it back to the original type before calling it.
>> So  g++ with -Wextra warns you that you have either made a mistake in
>> your code, or are trying to do something that is potentially dangerous.
>
> He needs to store different function-pointers with a common type;
> why not as a void-pointer ?

As far as I know, the standards do not define the behaviour of casting
between function pointers and void pointers (or any object pointers).
The C standards are clear about the matter - it is not defined
behaviour. But I don't know the C++ standards well enough to say.

For C, you can happily use "void (*)(void)" as a universal function
pointer type, rather than "* void" which is only for object pointers.

The compiler warning here is a good idea for most code, but sometimes
you need code that is potentially risky but you know is correct - such
as converting function pointer types before storing them, and converting
them back before using them. The OP just needs to disable the warning
around the code that does this conversion.

Re: Proper cast of function pointers

<v0apks$29mt8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3691&group=comp.lang.c%2B%2B#3691

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 13:15:40 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <v0apks$29mt8$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08hg4$1m0ss$2@dont-email.me> <v08ien$1ke8k$2@dont-email.me>
<v0apca$29jei$2@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 13:15:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e52005174aa1993ff22f62609fe4959";
logging-data="2415528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Emd3w4N+Hw5GXjeunUVIXddO6lMISouY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:iSNXXefiIexdNfRWOrk1sUdnAK0=
Content-Language: en-GB
In-Reply-To: <v0apca$29jei$2@raubtier-asyl.eternal-september.org>
 by: David Brown - Wed, 24 Apr 2024 11:15 UTC

On 24/04/2024 13:11, Bonita Montero wrote:
> Am 23.04.2024 um 17:00 schrieb Markus Schaaf:
>> Am 23.04.24 um 16:44 schrieb David Brown:
>>> On 23/04/2024 14:23, Markus Schaaf wrote:
>>>> Am 23.04.24 um 13:31 schrieb Paavo Helde:
>>>>>
>>>>> There is an old third-party library where some function pointers are
>>>>> casted to another type, then back to the original type before use. C++
>>>>> standard says this is kosher, and there have never been any problems
>>>>> with actual behavior. Alas, different versions and compile modes of
>>>>> g++
>>>>> still produce warnings. What would be the best way to silence them
>>>>> (without just switching off warnings)?
>>>>
>>>> You could use a union, if you know all possible function types
>>>> beforehand.
>>>>
>>>
>>> You /could/, if you don't mind the undefined behaviour - type-punning
>>> unions are not defined behaviour in C++.
>>
>> I have no idea what you are writing about. Of course one would read
>> the exact same member of the union one had written to before. That is
>> what unions are for.
>
> A union actually isn't needed for the discusses purpose.
> Just do a reinterpret_cast or a C-style cast.
>

Sure - that's what the OP is doing. It's not the cast that is his
problem - it is the compiler warning that he'd like to avoid.

Re: Proper cast of function pointers

<v0aq3l$29mt8$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3692&group=comp.lang.c%2B%2B#3692

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 13:23:33 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v0aq3l$29mt8$2@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08hg4$1m0ss$2@dont-email.me>
<v0apan$29jei$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 13:23:34 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e52005174aa1993ff22f62609fe4959";
logging-data="2415528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UldVgkD1hgF0BckOSX9ZK4fHwdMMTOxs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:PhwiPj8mHnkv8mIbGxZWndg0t0o=
Content-Language: en-GB
In-Reply-To: <v0apan$29jei$1@raubtier-asyl.eternal-september.org>
 by: David Brown - Wed, 24 Apr 2024 11:23 UTC

On 24/04/2024 13:10, Bonita Montero wrote:
> Am 23.04.2024 um 16:44 schrieb David Brown:
>
>> You /could/, if you don't mind the undefined behaviour - type-punning
>> unions are not defined behaviour in C++.
>
> Actually all compiler support that.

That may be true - but I am entirely confident that you don't know it is
true. You live in a little world where the only compiler is MSVC++ -
you know nothing about the hundred other C++ compilers out there. (I
know more of them than you - and more importantly, I know my knowledge
is limited.)

Compiler extensions can be useful - and sometimes essential. It's fine
to write non-portable code when you have to do so. It is a much worse
idea to use non-portable code when it is needless to do so. There's no
need to use type-punning unions in C++, so don't do it - even if it
happens to work on the compilers you tested.

> But MSVC++ isn't that efficient
> with that like clang or g++; MSVC often does a store and load round-
> trip. But there's bit_cast with C++20, which also works efficient
> with MSVC++.

Yes, std::bit_cast<> is (as I said) a good and well-defined alternative
to type-punning unions in C++20. And if you have to use a poor-quality
compiler that can't do a decent job of optimising memcpy, then it's
definitely the way to go for general type-punning uses.

> But actually he neither needs bit_cast nor unions for
> his purpose, but just a reinterpret_cast or a C-style cast, which
> I prefer for readability.
>

Agreed, in this particular case - and reinterpret_cast<> was the OP's
original choice.

Re: Proper cast of function pointers

<l8saimFgv2mU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3693&group=comp.lang.c%2B%2B#3693

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bo...@bo-persson.se (Bo Persson)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 14:00:21 +0200
Lines: 31
Message-ID: <l8saimFgv2mU1@mid.individual.net>
References: <v08672$1jh9c$1@dont-email.me> <v08hg0$1m0ss$1@dont-email.me>
<v0aj9s$28868$1@raubtier-asyl.eternal-september.org>
<v0apih$29msl$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net wfHL0/DmklKHi5KhLxCpqwC0uQJn8UrgDDncdPOUWwJEmFlpch
Cancel-Lock: sha1:fBmhtwnFbbdtvmPYxvHrecUCGn8= sha256:az860Ls38sXZP03VKajjdddspsALVhepYpz8ks9lxhk=
User-Agent: Mozilla Thunderbird
Content-Language: sv
In-Reply-To: <v0apih$29msl$1@dont-email.me>
 by: Bo Persson - Wed, 24 Apr 2024 12:00 UTC

On 2024-04-24 at 13:14, David Brown wrote:
> On 24/04/2024 11:27, Bonita Montero wrote:
>> Am 23.04.2024 um 16:44 schrieb David Brown:
>>
>>> The compiler is warning here about casting incompatible function
>>> types because usually such casts are a bad idea.  In particular,
>>> casting to
>>> a  different function type, then calling through this new type, is
>>> undefined behaviour.  About the only useful thing you can do with
>>> your cast pointer is cast it back to the original type before calling
>>> it.
>>> So  g++ with -Wextra warns you that you have either made a mistake in
>>> your code, or are trying to do something that is potentially dangerous.
>>
>> He needs to store different function-pointers with a common type;
>> why not as a void-pointer ?
>
> As far as I know, the standards do not define the behaviour of casting
> between function pointers and void pointers (or any object pointers).
> The C standards are clear about the matter - it is not defined
> behaviour.  But I don't know the C++ standards well enough to say.
>

This is something about theory and practice. A function pointer is
allowed to be larger than a void*.

In practice both Linux/Posix and Windows will use void* for returning
function pointers into dynamic libraries. So on those systems it will
obviously work.

Re: Proper cast of function pointers

<v0au56$2amfo$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3694&group=comp.lang.c%2B%2B#3694

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 15:32:36 +0300
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <v0au56$2amfo$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me>
<v086ut$1jkn4$1@raubtier-asyl.eternal-september.org>
<v08ut6$1p6m1$1@dont-email.me>
<v0acqb$26rt3$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 14:32:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4deac5886d6cd9d0437a896319444134";
logging-data="2447864"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18C7cqpRvonIBCfcJsfiKx5OqoxdTTzK2w="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:l9U6KDm4TT88CclsCwNlKjrqYIc=
Content-Language: en-US
In-Reply-To: <v0acqb$26rt3$1@raubtier-asyl.eternal-september.org>
 by: Paavo Helde - Wed, 24 Apr 2024 12:32 UTC

24.04.2024 10:36 Bonita Montero kirjutas:
> Am 23.04.2024 um 20:33 schrieb Paavo Helde:
>
>> The function pointers are cast to a single type so that they can be
>> stored in a common lookup array. ...
>
> Then you'd need additional information to distinguish the different
> types. If you have sth. like that you could take a variant<>.

Right, the varying part is the number of arguments, which is explicitly
declared and stored in the array as well (n_pars below). If you are
interested, the current code (no warnings any more here, thanks to
Markus!) looks like below. Not sure if changing to a variant or
void(*)() would make the code better, looks like then I would need to
add extra casts to all the lines in the table which currently do not
need any casts.

#include <math.h>

typedef double (*Func)(double);

struct formu_item {
const char *name;
Func f; /* pointer to function*/
int n_pars; /* number of parameters (0, 1, 2 or 3) */
int varying; /* Does the result of the function vary
even when the parameters stay the same?
varying=1 for e.g. random-number generators. */
};

typedef void (*VoidFunc)();
typedef double (*DoubleFunc_0_args)();
typedef double (*DoubleFunc_2_args)(double, double);

Func FuncCast2(DoubleFunc_2_args fp) {
return reinterpret_cast<Func>(reinterpret_cast<VoidFunc>(fp));
} Func FuncCast0(DoubleFunc_0_args fp) {
return reinterpret_cast<Func>(reinterpret_cast<VoidFunc>(fp));
} double pi() {
return 3.1415926535897932384626433832795029;
}

static const formu_item ftable_static[TABLESIZE]=
{ {"exp", exp,1,0},
{"ln", log,1,0},
{"sin", sin,1,0},
{"cos", cos,1,0},
{"tan", tan,1,0},
{"asin", asin,1,0},
{"acos", acos,1,0},
{"atan", atan,1,0},
{"atan2", FuncCast2(atan2),2,0},
{"abs", fabs,1,0},
{"sqrt", sqrt,1,0},
{"pi", FuncCast0(pi),0,0},
//...
}

Re: Proper cast of function pointers

<v0b5lu$2cd1g$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3695&group=comp.lang.c%2B%2B#3695

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 16:41:02 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v0b5lu$2cd1g$1@dont-email.me>
References: <v08672$1jh9c$1@dont-email.me> <v08hg0$1m0ss$1@dont-email.me>
<v0aj9s$28868$1@raubtier-asyl.eternal-september.org>
<v0apih$29msl$1@dont-email.me> <l8saimFgv2mU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 24 Apr 2024 16:41:03 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e52005174aa1993ff22f62609fe4959";
logging-data="2503728"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+OIMiO4XUHtc1NTbKj6Tap/gQ5CuBmux0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Kp7t3LDZ3V2cvqjzjXZU58HTpig=
Content-Language: en-GB
In-Reply-To: <l8saimFgv2mU1@mid.individual.net>
 by: David Brown - Wed, 24 Apr 2024 14:41 UTC

On 24/04/2024 14:00, Bo Persson wrote:
> On 2024-04-24 at 13:14, David Brown wrote:
>> On 24/04/2024 11:27, Bonita Montero wrote:
>>> Am 23.04.2024 um 16:44 schrieb David Brown:
>>>
>>>> The compiler is warning here about casting incompatible function
>>>> types because usually such casts are a bad idea.  In particular,
>>>> casting to
>>>> a  different function type, then calling through this new type, is
>>>> undefined behaviour.  About the only useful thing you can do with
>>>> your cast pointer is cast it back to the original type before
>>>> calling it.
>>>> So  g++ with -Wextra warns you that you have either made a mistake in
>>>> your code, or are trying to do something that is potentially dangerous.
>>>
>>> He needs to store different function-pointers with a common type;
>>> why not as a void-pointer ?
>>
>> As far as I know, the standards do not define the behaviour of casting
>> between function pointers and void pointers (or any object pointers).
>> The C standards are clear about the matter - it is not defined
>> behaviour.  But I don't know the C++ standards well enough to say.
>>
>
> This is something about theory and practice. A function pointer is
> allowed to be larger than a void*.
>
> In practice both Linux/Posix and Windows will use void* for returning
> function pointers into dynamic libraries. So on those systems it will
> obviously work.
>

Sure. But I saw nothing in the OP's posts to indicate that he was using
POSIX or Windows. And it is silly to use "void *" pointers for generic
function pointers when "void (*)(void)" will work be design, rather than
luck, and is in no way more difficult or less efficient. (Note that
this is what the OP is already doing.)

Re: Proper cast of function pointers

<v0b76d$2co20$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3696&group=comp.lang.c%2B%2B#3696

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 17:06:56 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <v0b76d$2co20$1@raubtier-asyl.eternal-september.org>
References: <v08672$1jh9c$1@dont-email.me> <v08985$1j0ue$3@dont-email.me>
<v08hg4$1m0ss$2@dont-email.me>
<v0apan$29jei$1@raubtier-asyl.eternal-september.org>
<v0aq3l$29mt8$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 24 Apr 2024 17:06:54 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="8489b4849e5ffcd9346751255d4a40b6";
logging-data="2515008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186CWu1L/wWPOJdl+KqA1OW07nAMzkl/yY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:hmvVLLYJ8b+pN6Q/MXX0HF91VYI=
Content-Language: de-DE
In-Reply-To: <v0aq3l$29mt8$2@dont-email.me>
 by: Bonita Montero - Wed, 24 Apr 2024 15:06 UTC

Am 24.04.2024 um 13:23 schrieb David Brown:

> That may be true - but I am entirely confident that you don't know it is
> true.  You live in a little world where the only compiler is MSVC++ -
> you know nothing about the hundred other C++ compilers out there.  (I
> know more of them than you - and more importantly, I know my knowledge
> is limited.)

Any C++ compiler supports that since this is very common and you
coudln't port a lot of code to compilers who wouldn't understand
that. I've no problem using a union since this feature is required
for any compiler to be conformant with a lot of software.

Re: Proper cast of function pointers

<v0b784$2co20$2@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3697&group=comp.lang.c%2B%2B#3697

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Proper cast of function pointers
Date: Wed, 24 Apr 2024 17:07:51 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <v0b784$2co20$2@raubtier-asyl.eternal-september.org>
References: <v08672$1jh9c$1@dont-email.me> <v08hg0$1m0ss$1@dont-email.me>
<v0aj9s$28868$1@raubtier-asyl.eternal-september.org>
<v0apih$29msl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 24 Apr 2024 17:07:49 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="8489b4849e5ffcd9346751255d4a40b6";
logging-data="2515008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HVmhKBQN9ZyPWJ2MXLgTgKfRGtCSg1GM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+KhjHNykrxLECJPuGCgGOKOmXdE=
In-Reply-To: <v0apih$29msl$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 24 Apr 2024 15:07 UTC

Am 24.04.2024 um 13:14 schrieb David Brown:

> As far as I know, the standards do not define the behaviour of casting
> between function pointers and void pointers (or any object pointers).
> The C standards are clear about the matter - it is not defined
> behaviour.  But I don't know the C++ standards well enough to say.

There's for sure no compiler which doesn't support that.


devel / comp.lang.c++ / Proper cast of function pointers

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor