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? I am passing the pointer together in an API which I do not control so I can not change the format of TY Variables with static storage allocations are started at zero by default Are there. Therefore, the following statements are effectively equivalent. There is a work scope in the variable 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 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; }
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).
Fixed circular_que * cir; // constant circular_queue * cir = 0 equals; // constant circular_queue * cir = NULL equals;
cir , that is, this function can be accessed in
get_char . Therefore, the answer to your question
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
Post a Comment