Go Down

Topic: Are these syntax just equivalent? (Read 46 times) previous topic - next topic

Delta_G

I have a function pointer in my program like so:

Code: [Select]

void (*ptrFunction)();

void callPtrFunc(){
     ptrFunction();
}



The call function gets called every loop and whatever function is registered there gets called.  Basic callback style programming.  And it works just fine. 

But I noticed in some of my code that I had registered the function two different ways and both were working.  Are these equivalent?  Or am I missing something deeper that allowed it to work but might have backfired later?  Which one is better?

Code: [Select]


ptrFunction = someFunction;

  //  or  //

ptrFunction = &someFunction;



It "appears" to work with or without the &, but I know how things can sometimes "appear" to work until you add the next bit of code. 

AWOL

The name of the function is the address of the function; the & is superfluous.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

RayLivingston

They are equivalent.  Arguably, adding the & makes it more clear, but they are functionally the same.

Regards,
Ray L.

Delta_G

Cool.  That's what I thought, but I wanted to make sure.  

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy