c - initializing a function externally -


I would like to return a function with a variable inside that I can initialize it inside the function that gives it Possible, or not? int get_char (char * c) {static circular_queue * cir; // It needs to be started in the function below if (circular_queue_empty (cir)) 0; Else * c = circular_queue_pop (cir); Return 1; } Int (* generate_get_char (circular_queue * cir)) (char * c) {// Circuit Return & amp; Do something to set get_char; }

I am passing the pointer together in an API which I do not control so I can not change the format of get_char ; It is being said that there is a better way to do this because I am quite sure that the above is not possible. (I will not use a static global, but all I can think of doing).

TY

Variables with static storage allocations are started at zero by default Are there. Therefore, the following statements are effectively equivalent.

  Fixed circular_que * cir; // constant circular_queue * cir = 0 equals; // constant circular_queue * cir = NULL equals;   

There is a work scope in the variable cir , that is, this function can be accessed in get_char . Therefore, the answer to your question

I would like to return a function with a variable inside that I can initialize it inside the function which it gives is possible, or is not it?

You do not need a global variable which is visible for both get_char and generate_get_char functions. Also, note that the name of a function indicates on the indicator. Therefore, the following are equivalent -

  return and get_char; // get_char equal to return;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -