Friday, 15 May 2015

objective c - C pass function call as variable -


This may be an unusual question (I'm sure the title is quite confusing), but it is possible in C / Objective C, to pass the actual function call to any other function without changing the signature? This means that once the function is attempted to get the value of the variable, what will be said? (I have tried with Function Points, but for this, I have to change the signature).

A better example of what I want to achieve in order to better understand. (Note that foo should be considered a private API)

  int foo (double A) {print (a); Print (a); Print (a); } Double GlobalCount = 1.0; Double count () {Return globalcount ++; } Int main () {foo (globalCount ()); // I know that this syntax will evaluate the globalcount (first) ...}   

expected output:

  1 2 3   

If some bad magic might be it I would really be happy ...

< P> It should:
  typed double double (* FUNC_PTR) (zero); Zero foo (FUNC_PTR funcPtr) {print ((* funcPtr) ()); Print ((* amp; PkPtr) ()); Print ((* amp; PkPtr) ()); } Double GlobalCount = 1.0; Double count () {Return globalcount ++; } Int main () {foo (and count); }    

No comments:

Post a Comment