Home My Page Projects Modern C
Summary Activity Forums Tracker News SCM Files

Forum: discussion

Monitor Forum | Start New Thread Start New Thread
RE: Function to Function-Pointer Decay [ Reply ]
By: Jens Gustedt on 2020-07-13 21:11
[forum:153518]
Let's try it again.

A function designator decays to a function pointer almost anywhere it is used, even if it is followed by parenthesis.

Jens

RE: Function to Function-Pointer Decay [ Reply ]
By: Some Guy on 2020-07-13 18:58
[forum:153517]
Thanks for your answer, but I'm still a little confused.

Do you mean that, ignoring any possible subsequent open parentheses `(`, a function `f` will decay if evaluating any combination of the `address-of` & and `object-of` * operators on it does not return a pointer type?

Again, thanks

RE: Function to Function-Pointer Decay [ Reply ]
By: Jens Gustedt on 2020-07-12 18:20
[forum:153515]
Hello,
ah, sorry I see why this might be confusing. Please read

"A function f without a following opening `(` decays to a pointer to its start"

as

"A function f without considering a possible opening `(` decays to a pointer to its start"

I hope this makes it clearer

Jens

Function to Function-Pointer Decay [ Reply ]
By: Some Guy on 2020-07-12 14:11
[forum:153514]
Dear Jens Gustedt,

I'm currently studying your wonderful `Modern C` book, but I'm stuck at understanding the concept `function to function-pointer decay` as explained in section `11.4`.

Takeaways 2.11.4.1 and 2.11.4.3 respectively state "A function f without a following opening `(` decays to a pointer to its start" and "The function call operator (...) applies to function pointers", but in the code snippet below the latter we find this:

-----
double f(double a);

// Equivalent calls to f, steps in the abstract state machine
f(3); // Decay → call
(&f)(3); // Address of → call
(*f)(3); // Decay → dereference → decay → call
(*&f)(3); // Address of → dereference → decay → call
(&*f)(3); // Decay → dereference → address of → call
-----
Since (...) applies to function pointers, it must carefully handle the case in which f is not a pointer, so it converts f into a function pointer, and then performs the actual call.

Now, let's consider the first example (it extends to the others as well).
As stated in takeaway 2.11.4.1, f is followed by an opening `(` so it should not decay, so why does the relative comment says "Decay → call"? Is the word `decay` used with a different meaning here?

Shouldn't the two operations defined in the previous two takeaways be assigned different names?

Thanks for your attention, and also for your awesome work.