Here is a small snippet of a program i am trying to understand, but can’t understand due to pointers.
/* issue JSON-RPC request */
val = json_rpc_call(curl, srv.rpc_url, srv.rpc_userpass, s);
if (!val) {
fprintf(stderr, "submit_work json_rpc_call failed\n");
goto out;
}
*json_result = json_is_true(json_object_get(val, "result"));
rc = true;
sharelog(remote_host, auth_user,
srv.easy_target ? "Y" : *json_result ? "Y" : "N",
*json_result ? "Y" : "N", NULL, hexstr);
if (debugging > 1)
applog(LOG_INFO, "[%s] PROOF-OF-WORK submitted upstream. "
"Result: %s",
remote_host,
*json_result ? "TRUE" : "false");
json_decref(val);
if (*json_result)
applog(LOG_INFO, "PROOF-OF-WORK found");
/* if pool server mode, return success even if result==false */
if (srv.easy_target)
*json_result = true;
out:
return rc;
My concern is this part:
/* if pool server mode, return success even if result==false */
if (srv.easy_target)
*json_result = true;
In my case srv.easy_target is true. Then json_result will be true as well, however that if statement is placed at the end of the function. I just don’t understand how json_result would be of use.
Or is the pointer going to pass that even before any of the code above is executed?
Basically how will that pointer placed at the end of the function be of any use?
json_resultis a pointer, probably a parameter from outside. Using*dereferences it and changes the value it points to.That is a pretty standard way of providing results from functions. The caller passes a pointer to its variable, and the callee does exactly what this code does: dereferences the passed pointer and changes the value it points to, thus changing the caller’s variable.