Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Without providing some extra code to store the parameter <em>'during'</em> the <em>'last'</em> call to your function there is no chance at all to detect if it was called with the same value or another.</p> <p>As the <em>'current'</em> value of x will be living on the stack only it will be completely lost once your function call finishes. </p> <p>In the <strong>pre-multi-threading</strong> era just using a static variable to cache the value of x during the last run of your function <code>func</code> could (almost) have solved your problem:</p> <pre><code>void fun (int x) { static int old_value = VALUE_INVALID; if(x != old_value) printf("VALUE OF X IS DIFFERENT THAN PREVIOUS CALL \n"); old_value = x; } </code></pre> <p>The only problem still staying with this approach is re-entrancy - meaning the cached value might get screwed up if <code>func</code> gets called in a signal handler.</p> <p>If running in a <strong>multi-threaded</strong> application you additionally have to provide some kind of locking mechanism when using this approach or you'll get pretty much screwed up sooner or later.</p> <p>Probably you'll be screwed up in this scenario anyways as you would have to clarify what <em>'last'</em> call to function and value <em>'during'</em> execution exactly mean.</p> <p>Is the current right value that of thread A that entered func before thread B but is still executing or that of thread B that entered after B but which has finished execution of func already? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload