Sujet : Re: Threads across programming languages
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++ comp.lang.cDate : 03. May 2024, 16:18:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v12v90$ju1r$1@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Mozilla Thunderbird
Am 03.05.2024 um 17:01 schrieb Michael S:
On Fri, 3 May 2024 13:23:13 +0200
Bonita Montero <Bonita.Montero@gmail.com> wrote:
Am 03.05.2024 um 11:18 schrieb David Brown:
On 03/05/2024 09:58, Bonita Montero wrote:
Am 03.05.2024 um 09:38 schrieb David Brown:
No it is not. C-style functions (or C++ functions for that
matter) are not objects, and do not have calling operators.
Built-in operators do not belong to a type, in the way that class
operators do.
>
You can assign a C-style function pointer to an auto
function-object.
>
A C-style function /pointer/ is an object. A C-style /function/ is
not. Do you understand the difference?
>
Practically there isn't a difference.
>
For C, I agree, mostly because C has no nested functions.
For C++ (after C++11) I am less sure, because of lambdas with
non-empty captures.
Lambdas without captures can be casted to C function-pointers and those
lambdas have all the same function-pointer type if the signature of the
calling operator is the same.
A nice trick to enforce function-pointer casting is to apply the +-ope-
rator to a non-capturing lambda since the plus-operator can be applied
to all pointers (I can really recommend the book "C++ Lambda Story" for
such details); this makes it possible to make the function-pointer defi-
nition type-inferenced. Or if you want to create a function<>-object
from the lambda which is guaranteed not to allocate if you pass a C
function-pointer you can enforce that if you attach the +-sign to the
assigned lambda.