Sujet : Re: Threads across programming languages
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 18. May 2024, 16:11:41
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86zfsnqhn6.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Michael S <
already5chosen@yahoo.com> writes:
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.
First, a pointer is not an object. In both C and C++, any pointer,
including a function pointer, is a scalar value. A pointer value
might be held in an object but it doesn't have to be. In most cases
function pointers are not stored in objects but simply used to call
the function pointed to.
A function is a static (not meant in the sense of the 'static'
keyword) program entity, usually arising as the result of giving a
function definition somewhere in the test of a program.
An expression with function type is a function designator. In most
cases function designators are simply the identifier used in the
definition that defines the function in question.
When the operand of an & operator is a function, the result of
evaluating the & expression is the address of the function
designated, or in other words a function pointer value. In most
other contexts a function designator is automatically converted
to a function pointer value when evaluated, as would have happened
if an & operator had been applied. (Applying a * operator to a
function pointer operand gives a function designator for the
pointed-to function.)
In the lambda world there isn't an exact analogue to the idea of a
function. There is the static text of a lambda expression, but that
doesn't define a "thing" any more than the text '3+4' defines a
"thing". Rather, when evaluated, a lambda expression produces a
lambda value, also known as a closure. A closure is a value like
other more familiar values: it can be used directly in a larger
expression, like the result of evaluating '3+4' might be used in an
expression like 'x[3+4]'; or it can be assigned thru an lvalue of
the appropriate type to be stored in an object.
The key point here is to distinguish between lambda expressions,
which are simply text strings and not "things", and the result of
evaluating a lambda expression, which are lambda values (closures).
Lambda values are like function pointers in that they are values
and can be dealt with as such, but they are not like function
pointers in that they don't point to anything; they are simply
values that can be used in conjunction with certain operators to
effect various program actions.
Disclaimer: I have not consulted any C++ standard to see if my
terminology here matches how terminology is used in C++.