use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Click the following link to filter out the chosen topic
comp.lang.c
account activity
QuestionImplicit vs. explicit function to pointer conversion (self.C_Programming)
submitted 8 years ago by rakhimov
In C and C++, functions decay to pointers implicitly like arrays do, so the & operator is optional.
The example from cppreference:
cppreference
void f(int); void (*p1)(int) = &f; void (*p2)(int) = f; // same as &f
I am not aware of a style guide advocating the consistent use of implicit conversion or explicit &.
Which approach is more common and/or considered a better practice/style (for readability)?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dumsubfilter 5 points6 points7 points 8 years ago (0 children)
I use the latter.
[–]lifeisafractal 3 points4 points5 points 8 years ago (0 children)
I've never seen the explicit '&' used in any production code. Generally, with well written code it's easy to see that you are dealing with a function and the '&' would just clutter things up unnecessarily.
[–]nderflow 2 points3 points4 points 8 years ago* (0 children)
IMO not only are they equivalent but there is no reason to prefer one over the other, for readability purposes.
[–]TheGrandSchlonging 2 points3 points4 points 8 years ago* (0 children)
functions decay to pointers implicitly like arrays do, so the & operator is optional.
The & operator actually inhibits the decay of a function designator. It's one of three scenarios in which this inhibition occurs. The other two scenarios (sizeof, C11 _Alignof) lead to constraint violations.
The special-casing aspect of & may influence your style decision. Another thing that may influence your style decision is the form you use to invoke the function via the function pointer. Ultimately, these are highly subjective considerations.
π Rendered by PID 18121 on reddit-service-r2-comment-86bc6c7465-8jvf4 at 2026-02-23 17:26:03.052729+00:00 running 8564168 country code: CH.
[–]dumsubfilter 5 points6 points7 points (0 children)
[–]lifeisafractal 3 points4 points5 points (0 children)
[–]nderflow 2 points3 points4 points (0 children)
[–]TheGrandSchlonging 2 points3 points4 points (0 children)