Re: Cannot understand the following codes



On 2006-03-29, Arthur J. O'Dwyer <ajonospam@xxxxxxxxxxxxxx> wrote:
On Wed, 29 Mar 2006, Ben C wrote:
[..] The difference between (*r) and (r) is that (*r) is the thing
pointed to by 'r', which is of function type, which, in this context,
immediately decays back to a function pointer. (r) is just that same
function pointer, without the dereference and decay. In other words,
(*r) decays to (r). Therefore, both expressions have the /exact same/
behavior.

I think more old code used the (*f)(x) style, and newer code, maybe
influenced by C++ and Lispy languages, uses plain old f(x) more often.
I tend to use (*cmp)(x,y) for callback functions in things like 'qsort',
but if I were writing something like

int (*printme)() = (widget == on)? magic: more_magic;

I'd use

printme(x);

instead.

Thanks. I tend to use (*f) just as a hint to the reader that it's an
indirect call.
.



Relevant Pages

  • Re: Cannot understand the following codes
    ... I had assumed void * was good for anything. ... int x =; or even ... is just that same function pointer, ... In other words, decays to. ...
    (comp.programming)
  • Re: page 120 K&R
    ... function you are actually calling it via the function pointer. ... reference to that function is simply a reference to it's address. ... Note that one difference is that an array name "decays" to a pointer to its first element where as a function name gives a pointer to the function as a whole, ...
    (comp.lang.c)
  • Re: A function is an address
    ... standard in terms of semantics, ... To keep things in context, this is in reference to describing ... avoid confusion long enough to get started. ... A function pointer will typically contain an address, ...
    (comp.lang.c)